PlaceOrderExecutor Class
Namespace
Example
CommerceOrders.PlaceOrderResult resp = CommerceOrders.PlaceOrderExecutor.execute(graph,internalEnum,cEnum,cInput,catalogRatesPreference);
PlaceOrderExecutor Methods
The PlaceOrderExecutor class includes these methods.
execute(graphRequest, pricingPreferenceEnum, configurationInputEnum, configurationOptionsInput)
Signature
public static commerceorders.PlaceOrderResult execute(commerceorders.GraphRequest graphRequest, commerceorders.PricingPreferenceEnum pricingPreferenceEnum, commerceorders.ConfigurationInputEnum configurationInputEnum, commerceorders.ConfigurationOptionsInput configurationOptionsInput)
Parameters
- graphRequest
- Type: commerceorders.GraphRequest
- The sObject graph values of the order payload to be ingested.
- pricingPreferenceEnum
- Type: commerceorders.PricingPreferenceEnum
- Pricing preference during the order process.
- configurationInputEnum
- Type: commerceorders.ConfigurationInputEnum
- Configuration input for the place order process.
- configurationOptionsInput
- Type: commerceorders.ConfigurationOptionsInput
- Configuration options during the ingestion process.
Return Value
execute(graphRequest, pricingPreferenceEnum, catalogRatesPreference, configurationInputEnum, configurationOptionsInput)
Signature
public static commerceorders.PlaceOrderResult execute(commerceorders.GraphRequest graphRequest, commerceorders.PricingPreferenceEnum pricingPreferenceEnum, commerceorders.CatalogRatesPreferenceEnum catalogRatesPreferenceEnum, commerceorders.ConfigurationInputEnum configurationInputEnum, commerceorders.ConfigurationOptionsInput configurationOptionsInput)
Parameters
- graphRequest
- Type: commerceorders.GraphRequest
- The sObject graph values of the order payload to be ingested.
- pricingPreferenceEnum
- Type: commerceorders.PricingPreferenceEnum
- Pricing preference during the order process.
- catalogRatesPreference
- Type: commerceorders.CatalogRatesPreferenceEnum
- The rate card entries defined in the catalog that must be fetched for order items, with usage-based pricing during the order creation process. The CatalogRatesPreferenceEnum enum is available when the Usage-Based Selling feature is enabled.
- configurationInputEnum
- Type: commerceorders.ConfigurationInputEnum
- Configuration input for the place order process.
- configurationOptionsInput
- Type: commerceorders.ConfigurationOptionsInput
- Configuration options during the ingestion process.
Return Value
execute(graphRequest)
Signature
public static commerceorders.PlaceOrderResult execute(commerceorders.GraphRequest graphRequest)
Parameters
- graphRequest
- Type: commerceorders.GraphRequest
- The sObject graph values of the order payload to be ingested.
Return Value
PlaceOrderExecutor Example Implementation
Namespace
Usage
Customize this example to suit your requirements. Create the list of records to be ingested by using these steps. Replace the respective IDs with the values that are present in your org. For example, replace the value of ${Pricebook2Id} field with the price book ID that’s present in the org.
Example
- Create the list of records by constructing the Map<String, Object> map of field
values of an
order.
List<CommerceOrders.RecordWithReferenceRequest> recordNodes = new List<CommerceOrders.RecordWithReferenceRequest>(); // Prepare for the Order Map<String,Object> orderFieldValues = new Map<String,Object>(); orderFieldValues.put('Pricebook2Id', '01sDU0000000lEIYAY'); orderFieldValues.put('AccountId', '001DU000001nIPKYA2'); orderFieldValues.put('EffectiveDate', '2024-01-01');
- To create a record object from the field values, create an instance of the
RecordResource
class.
CommerceOrders.RecordResource orderRecord = new CommerceOrders.RecordResource(Order.getSobjectType(), 'POST'); orderRecord.fieldValues = orderFieldValues;
- To associate the Record object with a reference identifier, create an instance
of the RecordWithReferenceRequest
class.
CommerceOrders.RecordWithReferenceRequest orderRecordNode = new CommerceOrders.RecordWithReferenceRequest('refOrder', orderRecord); recordNodes.add(orderRecordNode); // Prepare for the App Usage Assignment Map<String,Object> auaFieldValues = new Map<String,Object>(); auaFieldValues.put('AppUsageType', 'RevenueLifecycleManagement'); auaFieldValues.put('RecordId', '@{refOrder.id}'); CommerceOrders.RecordResource auaRecord = new CommerceOrders.RecordResource(AppUsageAssignment.getSobjectType(), 'POST'); auaRecord.fieldValues = auaFieldValues; CommerceOrders.RecordWithReferenceRequest auaRecordNode = new CommerceOrders.RecordWithReferenceRequest('refAppTag', auaRecord); recordNodes.add(auaRecordNode); // Prepare for the Order Item Map<String,Object> oiFieldValues = new Map<String,Object>(); oiFieldValues.put('OrderId', '@{refOrder.id}'); oiFieldValues.put('PricebookEntryId', '01uDU000000YPkIYAW'); oiFieldValues.put('Product2Id', '01tDU000000ESCSYA4'); oiFieldValues.put('Quantity', 2); oiFieldValues.put('UnitPrice', 800); CommerceOrders.RecordResource oiRecord = new CommerceOrders.RecordResource(OrderItem.getSobjectType(), 'POST'); oiRecord.fieldValues = oiFieldValues; CommerceOrders.RecordWithReferenceRequest oiRecordNode = new CommerceOrders.RecordWithReferenceRequest('refOrderItem', oiRecord); recordNodes.add(oiRecordNode);
- Invoke the Place Order Apex API.
// Invoke the Place Order Apex API CommerceOrders.PricingPreferenceEnum pricingPreference = CommerceOrders.PricingPreferenceEnum.System; CommerceOrders.CatalogRatesPreferenceEnum catalogRatesPreference = CommerceOrders.CatalogRatesPreferenceEnum.Fetch; CommerceOrders.ConfigurationInputEnum configurationPreference = CommerceOrders.ConfigurationInputEnum.RunAndAllowErrors; CommerceOrders.ConfigurationOptionsInput configurationInput = new CommerceOrders.ConfigurationOptionsInput(); configurationInput.validateProductCatalog = true; configurationInput.validateAmendRenewCancel = true; configurationInput.executeConfigurationRules = true; configurationInput.addDefaultConfiguration = true;
- To contain all record objects, create an instance of the GraphRequest
class.
CommerceOrders.GraphRequest graph = new CommerceOrders.GraphRequest('testGraph', recordNodes); CommerceOrders.PlaceOrderResult result = CommerceOrders.PlaceOrderExecutor.execute(graph, pricingPreference, catalogRatesPreference, configurationPreference, configurationInput); // Process any error, if exists if (!result.success) { List<ConnectApi.PlaceOrderErrorResponse> errors = result.responseError; for (ConnectApi.PlaceOrderErrorResponse error : errors) { System.debug(error.errorCode + ': ' + error.message); } }