Expand Data Sources for Return Insights

Extensions are a mechanism for using Apex to customize the functionality that powers B2B and B2C Commerce storefronts. The custom Apex class that implements an extension is called an extension provider. To extend or override the Product Expand API functionality, use the Commerce Order Management Product Expand Extension.

To start, extend the base class, commerce_ordermanagement.ProductExpandService.

Override the returnReasons method of commerce_ordermanagement.ProductExpandService, which is used to get the product’s return reasons. In this example, the entire method is replaced with custom logic to extract product data from ProductExpandRequest, set the return reasons, and process the ProductExpandResponse. You can also fetch the return reasons from an external service.

Instead of replacing the entire method with custom logic, you can call the base method with the super() method. You can still insert custom logic before and after the super() call.

To get the return reasons from an external service, define a custom private method.

You can create extension classes that can:

  • Replace the entire default implementation of each base class method with custom logic.
  • Add custom logic before calling the default implementation of a base class method.
  • Add customer logic after calling the default implementation of a base class method.
  • Add custom methods and classes.

To learn how to add your own Apex classes to a Salesforce org, see Adding an Apex Class.

Before you can fill an extension slot with a custom extension provider, create a web store. Register the extension class, and map the extension class to a B2C or D2C Commerce store. If you don’t have a web store, create a dummy web store in your Developer Console. Go to Debug, open Execute Anonymous Window, and paste this code.

Click Execute.

To fetch the web store ID, execute this SOQL query

and pick the web store ID from the returned values. Map your web store’s ID to the EPN.

To register and map extension classes, we recommend using Salesforce CLI and the Salesforce Commerce plug-in for sfdx. To manage extensions, use the latest version of Salesforce CLI. For detailed instructions, install Salesforce CLI and update Salesforce CLI.

To install the plug-in, run sfdx plugins:install @salesforce-commerce.

Example commands. The store-ID is the web store ID.

See Also