---
schema_version: "1"
id: d30e8a47df3da338bd55a9e998e13306b7a6899191c72831f6bf56b2564882b3
title: Use External Data Sources for Expected Quantity in Cycle Counts
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/ind/264-0-0/admin_intelligent_sales_cycle_count_apex.md
canonical_url: https://help.salesforce.com/s/articleView?id=ind.admin_intelligent_sales_cycle_count_apex.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 8bfb8a34862c23cc1d187f50eadbfa48d07cc6392be74327bdae983e0849d221
description: Expected quantities in cycle counts are automatically calculated from product item records in Intelligent Sales. However, if you need to use external data sources for these numbers, use our IFetchInventoryCount Apex Interface with your own custom Apex classes and methods.
products:
  - Life Sciences
release: "264"
---
# Use External Data Sources for Expected Quantity in Cycle Counts

Expected quantities in cycle counts are automatically calculated from product item records in Intelligent Sales. However, if you need to use external data sources for these numbers, use our IFetchInventoryCount Apex Interface with your own custom Apex classes and methods.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition">
        <colgroup>
          <col>
        </colgroup>
        <tbody>
          <tr class="">
            <td class="slds-cell-wrap" style="vertical-align:top;">
              <p>Available in: Lightning Experience</p>
              <p style="margin-bottom:0;">Available in: <strong>Enterprise</strong> and <strong>Unlimited</strong> Editions with Health Cloud
                or Life Sciences Cloud</p>
            </td>

          </tr>
        </tbody>
      </table> <table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small permission">
        <colgroup>
          <col style="width:50%">
          <col style="width:50%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="colgroup" class="slds-cell-wrap" colspan="2" style="text-align:center;vertical-align:top;" id="d168712e66">User
              Permissions Needed</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d168712e66 ">To define an Apex class:</td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d168712e66 ">Author Apex</td>

          </tr>
        </tbody>
      </table>

1. In the Developer Console, select **File** | **New** | **Apex Class**.
2. Implement this Apex interface in the Apex class:
    
    ```
    public class UpdateInventory implements healthcloudext.IFetchInventoryCount{
    //Sample Apex Class to fetch Inventory count from external Inventory Location (Input parameter : visitId)
        public Map<Id,Integer> getInventoryCount(String visitId){
    		 Map<Id,Integer> sample = new Map<Id,Integer>();        
        	    //Logic to fetch numbers from external data source
     	        //Use Apex code to connect to external API and fetch result  
            	//Return Type: Map of Product Item Id against its Count(Integer Value)
            return sample;
        }
    }
    ```

If any record against `ProductItemId` is missing a value, and that product item already has a value for expected quantity in the Intelligent Sales system, then the value in the Intelligent Sales system is used instead.