Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

ccrz.ccApiProduct.fetch

Executes a SOQL query of product records, and returns a list of products that match your query. This method can also return multiple lists of related object records, such as composite products and product media.

Compatibility

This reference applies to:

Release Managed Package Version API Version
B2B Commerce for Visualforce Winter ’21 4.13 12
B2B Commerce for Visualforce Spring ’20 4.12 11
B2B Commerce for Visualforce Summer ’19 4.11 10
B2B Commerce for Visualforce Spring ’19 4.10 9
B2B Commerce for Visualforce Summer ’18 4.9 8

You can still call older versions of the API for this method, which can accept different input keys or return different output keys. Any differences in behavior for older versions aren't documented in this topic.

Note

Signature

global static Map<String, Object> fetch(Map<String, Object>)

Service Layer Classes

Data Service Provider
ccrz.ccServiceProduct
Logic Service Provider
ccrz.ccLogicProductPricing

Inputs (Required)

Map<String, Object> that must include the following required keys:

ccrz.ccApi.API_VERSION
The version of the B2B Commerce for Visualforce API to reference for the method call. We recommend that you use the ccrz.ccApi.CURRENT_VERSION constant whenever possible, and only reference a specific version for compatibility if necessary.

If this key isn't specified, the method returns a ccrz.ccApi.NoApiVersionException.

Note

Include either of the following keys, but not both. If you don't include either key, the method returns a ccrz.ccApi.MissingInputException.

ccrz.ccApiProduct.PRODUCTIDLIST
Set<String> of specific product IDs to query:
new Set<String>{'Product_ID_1', 'Product_ID_2'}
ccrz.ccApiProduct.PRODUCTSKULIST
Set<String> of specific product SKUs to query:
new Set<String>{'Product_SKU_1', 'Product_SKU_2'}

If you specify both keys, ccrz.ccApiProduct.PRODUCTIDLIST takes precedence.

Note

Inputs (Optional)

The input map can also include the following keys:

ccrz.ccApi.API_SIZING
Map<String, Object> that specifies the scope of data that this method returns, including which fields the method returns for each record that matches the query.
ccrz.ccApiProduct.DATEFILTER
Boolean
Value Usage
true (default) Evaluate Start Date and End Date values when returning product data.
false Ignore Start Date and End Date values when returning product data.
ccrz.ccApiProduct.INCLUDE_ATTRIBUTE_PRICING
Boolean
Value Usage
true Evaluate attribute data when ccrz.ccApiProduct.PARAM_INCLUDE_PRICING is also true. B2B Commerce for Visualforce calls the ccrz.ccLogicProductPricing logic service class, which:
  • Queries for ccrz__E_Attribute__c records that are related to each product
  • Returns the attribute pricing JSON applied to the product's entitled price list item
false (default) Don't return any attribute pricing.
ccrz.ccApiProduct.MEDIAFILTER
Set<String> of specific product media types that you want to return in the related ccrz__E_ProductMedia__c records.
ccrz.ccApiProduct.PARAM_BY_ASC
Boolean
Value Usage
true Sort returned products by ID in ascending order. For example, sort from 100 to 900. If you pass ccrz.ccApiProduct.PARAM_BY_SEQ => true, products sort by Sequence value in ascending order.
false (default) Sort returned products by ID in descending order.
ccrz.ccApiProduct.PARAM_BY_NULLS_LAST
Boolean
Value Usage
true Place all products with a null Sequence value at the end of the returned product data.
false (default) Place all products with a null Sequence value at the beginning of the returned product data.
ccrz.ccApiProduct.PARAM_BY_SEQ
Boolean
Value Usage
true Sort returned products by Sequence value in descending order. For example, sort from 900 to 100.
false (default) Sort returned products by ID in descending order.
ccrz.ccApiProduct.PARAM_INCLUDE_BLOCKED
Boolean
Value Usage
true Return products with any status.
false (default) Return products with a status of only Released or Not Orderable.
ccrz.ccApiProduct.PARAM_INCLUDE_PRICING
Boolean
Value Usage
true (default) Include ccrz.ccApiProduct.PRODUCTPRICINGDATA in the product return data. B2B Commerce for Visualforce calls the ccrz.ccLogicProductPricing logic service class to evaluate each product's entitlements when determining pricing.
false Don't return any pricing data.
ccrz.ccApiProduct.PARAM_INCLUDE_SELLERS
Boolean
Value Usage
true (default) Return a list of all sellers for each product. Make sure that ccrz.ccApiProduct.PARAM_INCLUDE_PRICING is also true.
false Don't return any seller information.
ccrz.ccApiProduct.PARSE_ATTRIBUTE_PRICING
Boolean
Value Usage
true (default) Parse the attribute pricing JSON returned when ccrz.ccApiProduct.INCLUDE_ATTRIBUTE_PRICING is true.
false Skip querying attribute records and return only an unparsed attribute pricing field from each product's entitled price list item.
ccrz.ccApiProduct.PRODUCTLOCALE
String that specifies one of your storefront's supported locales. The method returns internationalized product values in the ccrz.ccApiProduct.PRODUCTLIST return key. The service layer translates the values from ccrz__E_ProductItemI18N__c records and handles fallback languages, if necessary.

If the input data doesn't include this key, the method falls back to ccrz.cc_CallContext.userLocale.

Note

ccrz.ccApiProduct.PRODUCTSTOREFRONT
String that specifies the name of a storefront for filtering the query.

If the input data doesn't include this key, the method falls back to ccrz.cc_CallContext.storefront.

Note

ccrz.ccApiProduct.TYPES
Set<String> of specific product types to query for.

Outputs

Map<String, Object> that can include the following keys:

ccrz.ccApi.API_VERSION
Integer that indicates which API version was used for the query.
ccrz.ccApi.SUCCESS
Boolean
Value Usage
true The call completed.
false The call encountered errors.

B2B Commerce for Visualforce doesn't always return an exception for any errors that can occur. When this value is false, consider rolling back the API transaction to a previous savepoint.

Tip

ccrz.ccApiAttribute.IDS
List<String> of entitled attribute records to pass to the ccrz.ccApiAttribute.fetch method for returning attributes related to the returned products. This data is available only when you include ccrz.ccApiProduct.PARAM_INCLUDE_PRICING => true in the input map.
ccrz.ccApiProduct.PRODUCTLIST
List<Map<String, Object>>, where each Map<String, Object> represents a ccrz__E_Product__c that matches the query.

To specify which fields the API returns for each product record, request a specific data size for the ccrz.ccApiProduct.ENTITYNAME key in your input data:

ccrz.ccApi.SIZING => new Map<String, Object> {
    ccrz.ccApiProduct.ENTITYNAME => new Map<String, Object> {
        ccrz.ccApi.SZ_DATA => ccrz.ccApi.SZ_M
    }
}

For information about which fields and related lists (such as product media) are available with different data sizes, see the ccrz__E_Product__c reference.

Tip

ccrz.ccApiProduct.PRODUCTPRICINGDATA
Map<String, Object> of the pricing data returned when you include ccrz.ccApiProduct.PARAM_INCLUDE_PRICING => true in the input map. This map contains seller, subscription term, attribute, and standard pricing information for the returned products.
ccrz.ccApiSpec.SPECLIST
List<Map<String, Object>>, where each Map<String, Object> represents a ccrz__E_Spec__c record associated with product spec values, which are included in the productSpecs field of ccrz.ccApiProduct.PRODUCTLIST. For more information about fetching spec data, see ccrz.ccApiSpec.fetch.

To specify which fields the API returns for each spec record, request a specific data size for the ccrz.ccApiSpec.ENTITYNAME key in your input data. You can request unique sizes for product data and spec data:

ccrz.ccApi.SIZING => new Map<String, Object> {
    ccrz.ccApiProduct.ENTITYNAME => new Map<String, Object> {
        ccrz.ccApi.SZ_DATA => ccrz.ccApi.SZ_M
    },
    ccrz.ccApiSpec.ENTITYNAME => new Map<String, Object> {
        ccrz.ccApi.SZ_DATA => ccrz.ccApi.SZ_L
    }
}

By default, the ccrz.ccApiSpec.SPECLIST is returned when the input map requests a large data size for ccrz.ccApiProduct.ENTITYNAME. You can optionally exclude the spec records from the return data.

ccrz.ccApi.SIZING => new Map<String, Object> {
    ccrz.ccApiProduct.ENTITYNAME => new Map<String, Object> {
        ccrz.ccApi.SZ_DATA => ccrz.ccApi.SZ_L,
        ccrz.ccApi.SZ_ASSC => false
    }
}

Tip

ccrz.ccApiSubProdTerm.SPTLIST
List<Map<String, Object>> of subscription product terms related to the returned products.
ccrz.ccApiSubProdTerm.SPTBYPRODID
Map<String, Object> of subscription product terms per product.

Example

Query a pair of product IDs, and capture the first product's name in a variable.

Map<String, Object> productFetchQuery = new Map<String, Object>{
    ccrz.ccApi.API_VERSION => ccrz.ccAPI.CURRENT_VERSION,
    ccrz.ccApiProduct.PRODUCTIDLIST => new Set<String>{'Product_ID_1', 'Product_ID_2'},
    ccrz.ccApi.SIZING => new Map<String, Object> {
        ccrz.ccApiProduct.ENTITYNAME => new Map<String, Object> {
            ccrz.ccApi.SZ_DATA => ccrz.ccApi.SZ_S
        }
    }
};

try {
    Map<String, Object> productFetchData = ccrz.ccApiProduct.fetch(productFetchQuery);
    if (productFetchData.get(ccrz.ccApiProduct.PRODUCTLIST) != null) {
        List<Map<String, Object>> myProductDataList = (List<Map<String, Object>>) productFetchData.get(ccrz.ccApiProduct.PRODUCTLIST);
        String productName = (String) myProductDataList[0].get('sfdcName');
    }
} catch (Exception e) {
    // Error handling...
}

Platform Cache

By default, this method checks for product data previously queried and stored in Platform Cache. This design helps improve performance on your storefront when displaying your product data.

The underlying ccrz.ccServiceProduct.fetch method that supports the ccrz.ccApiProduct.fetch method checks the Platform Cache for product data.

  1. Before the ccrz.ccApiProduct.fetch method executes the query for product data, the underlying ccrz.ccServiceProduct.fetch data service method calls the ccrz.ccService.prepareCacheKey method.
  2. If ccrz.ccService.prepareCacheKey finds a match in Platform Cache for the queried data, it passes the matching data to the ccrz.ccService.prepReturn method, which sends the data to the ccrz.ccApiProduct.fetch query.

If no matching data is found in the Platform Cache, the ccrz.ccApiProduct.fetch query executes and returns data from your org's database. In this case, the ccrz.ccService.prepareCacheData method is called to store the product data in Platform Cache.

Storing product data in Platform Cache also stores related data, such as product media and product specs, all of which consume space allocated in the cache.

Note

To specify how long B2B Commerce for Visualforce keeps product data cached, change the product data time to live (TTL) values in your storefront configuration settings.