Registering a custom Apex integration and mapping it to a store
Key Takeaway
After you write the Apex class, register it in RegisteredExternalService, then map that registration to a store in StoreIntegratedService.
A custom Apex integration lets a B2B store use your own code for a checkout calculation, such as price, inventory, shipping, or tax. Writing the Apex class is only the first step. Think of the next two steps this way: registration says what the class does, and mapping says which store uses it.
How to set up a custom Apex integration
An integration's Apex class implements one of four interfaces. The table pairs each interface with its ExternalServiceProviderType value and an example DeveloperName. You configure one provider for each type.
| Interface | ExternalServiceProviderType | Example DeveloperName |
|---|---|---|
sfdc_checkout.CartInventoryValidation | Inventory | CHECK_INVENTORY |
sfdc_checkout.CartPriceCalculations | Price | COMPUTE_PRICE |
sfdc_checkout.CartShippingCharges | Shipment | COMPUTE_SHIPPING |
sfdc_checkout.CartTaxCalculations | Tax | COMPUTE_TAXES |
- Create an Apex class that implements the interface for your calculation.
- Register the class by inserting a
RegisteredExternalServicerecord. Its key fields are:ExternalServiceProviderId: the Id of the Apex classExternalServiceProviderType: the kind of provider, which is the value paired with the class's interfaceDeveloperNameMasterLabel
- Map the registration to a store by inserting a
StoreIntegratedServicerecord. Its three required fields are:Integration: theRegisteredExternalServiceId or[ServiceProviderType]__[DeveloperName], joined with two underscores, such asPrice__COMPUTE_PRICEServiceProviderType: a value that must matchExternalServiceProviderTypeon theRegisteredExternalServicerecordStoreId: the Id of theWebStore
Ana has an Apex class that implements sfdc_checkout.CartShippingCharges, and she wants one store to use it. She registers the class with its Id in ExternalServiceProviderId, Shipment in ExternalServiceProviderType, and COMPUTE_SHIPPING in DeveloperName. She then inserts a StoreIntegratedService record with Shipment in ServiceProviderType, her WebStore Id in StoreId, and the new RegisteredExternalService Id in Integration. The value Shipment__COMPUTE_SHIPPING would also work in Integration.