PlaceOrderExecutor Class

Contains methods to place an order with details of the graph request, pricing preferences, and configuration options.

Namespace 

CommerceOrders

Example 

1CommerceOrders.PlaceOrderResult resp = CommerceOrders.PlaceOrderExecutor.execute(graph,internalEnum,cEnum,cInput,catalogRatesPreference);
  • PlaceOrderExecutor Methods

    Learn more about the methods available with the PlaceOrderExecutor class.

  • PlaceOrderExecutor Example Implementation

    Place orders with integrated pricing, configuration, and validation, and manage them throughout their entire lifecycle. To place an order from Apex, refer to the example implementation of the PlaceOrderExecutor class.

PlaceOrderExecutor Methods 

Learn more about the methods available with the PlaceOrderExecutor class.

The PlaceOrderExecutor class includes these methods.

execute(graphRequest, pricingPreferenceEnum, configurationInputEnum, configurationOptionsInput) 

Use the method in the PlaceOrderExecutor class to execute the Place Order Apex API request by assigning the properties for graph request, pricing reference, and configuration options.

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 

Type: commerceorders.PlaceOrderResult

execute(graphRequest, pricingPreferenceEnum, catalogRatesPreference, configurationInputEnum, configurationOptionsInput) 

Use the method in the PlaceOrderExecutor class to execute the Place Order Apex API request by assigning the properties for graph request, pricing reference, and configuration options. This method also includes the property to define fetching of rate card entries.

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 

Type: commerceorders.PlaceOrderResult

execute(graphRequest) 

Use the method in the PlaceOrderExecutor class to execute the Place Order Apex API request by assigning the properties for graph request.

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 

Type: commerceorders.PlaceOrderResult

PlaceOrderExecutor Example Implementation 

Place orders with integrated pricing, configuration, and validation, and manage them throughout their entire lifecycle. To place an order from Apex, refer to the example implementation of the PlaceOrderExecutor class.

Namespace 

commerceorders

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.

    1List<CommerceOrders.RecordWithReferenceRequest> recordNodes = new List<CommerceOrders.RecordWithReferenceRequest>();
    2    
    3// Prepare for the Order 
    4Map<String,Object> orderFieldValues = new Map<String,Object>();
    5orderFieldValues.put('Pricebook2Id', '01sDU0000000lEIYAY');
    6orderFieldValues.put('AccountId', '001DU000001nIPKYA2');
    7orderFieldValues.put('EffectiveDate', '2024-01-01');
  • To create a record object from the field values, create an instance of the RecordResource class.

    1CommerceOrders.RecordResource orderRecord = new CommerceOrders.RecordResource(Order.getSobjectType(), 'POST');
    2orderRecord.fieldValues = orderFieldValues;
  • To associate the Record object with a reference identifier, create an instance of the RecordWithReferenceRequest class.

    1CommerceOrders.RecordWithReferenceRequest orderRecordNode = new CommerceOrders.RecordWithReferenceRequest('refOrder', orderRecord);
    2recordNodes.add(orderRecordNode);
    3
    4// Prepare for the App Usage Assignment
    5Map<String,Object> auaFieldValues = new Map<String,Object>();
    6auaFieldValues.put('AppUsageType', 'RevenueLifecycleManagement');
    7auaFieldValues.put('RecordId', '@{refOrder.id}');
    8
    9CommerceOrders.RecordResource auaRecord = new CommerceOrders.RecordResource(AppUsageAssignment.getSobjectType(), 'POST');
    10auaRecord.fieldValues = auaFieldValues;
    11
    12CommerceOrders.RecordWithReferenceRequest auaRecordNode = new CommerceOrders.RecordWithReferenceRequest('refAppTag', auaRecord);
    13recordNodes.add(auaRecordNode);
    14
    15// Prepare for the Order Item
    16Map<String,Object> oiFieldValues = new Map<String,Object>();
    17oiFieldValues.put('OrderId', '@{refOrder.id}');
    18oiFieldValues.put('PricebookEntryId', '01uDU000000YPkIYAW');
    19oiFieldValues.put('Product2Id', '01tDU000000ESCSYA4');
    20oiFieldValues.put('Quantity', 2);
    21oiFieldValues.put('UnitPrice', 800);
    22
    23CommerceOrders.RecordResource oiRecord = new CommerceOrders.RecordResource(OrderItem.getSobjectType(), 'POST');
    24oiRecord.fieldValues = oiFieldValues;
    25
    26CommerceOrders.RecordWithReferenceRequest oiRecordNode = new CommerceOrders.RecordWithReferenceRequest('refOrderItem', oiRecord);
    27recordNodes.add(oiRecordNode);
  • Invoke the Place Order Apex API.

    The CatalogRatesPreferenceEnum enum is available when the Usage-Based Selling feature is enabled.

    Note

    1// Invoke the Place Order Apex API
    2CommerceOrders.PricingPreferenceEnum pricingPreference = CommerceOrders.PricingPreferenceEnum.System;
    3CommerceOrders.CatalogRatesPreferenceEnum catalogRatesPreference = CommerceOrders.CatalogRatesPreferenceEnum.Fetch;
    4CommerceOrders.ConfigurationInputEnum configurationPreference = CommerceOrders.ConfigurationInputEnum.RunAndAllowErrors;
    5CommerceOrders.ConfigurationOptionsInput configurationInput = new CommerceOrders.ConfigurationOptionsInput();
    6configurationInput.validateProductCatalog = true;
    7configurationInput.validateAmendRenewCancel = true;
    8configurationInput.executeConfigurationRules = true;
    9configurationInput.addDefaultConfiguration = true;
  • To contain all record objects, create an instance of the GraphRequest class.

    1CommerceOrders.GraphRequest graph = new CommerceOrders.GraphRequest('testGraph', recordNodes);
    2CommerceOrders.PlaceOrderResult result = CommerceOrders.PlaceOrderExecutor.execute(graph, pricingPreference, catalogRatesPreference, configurationPreference, configurationInput);
    3
    4
    5// Process any error, if exists
    6if (!result.success) {
    7  List<ConnectApi.PlaceOrderErrorResponse> errors = result.responseError;
    8  for (ConnectApi.PlaceOrderErrorResponse error : errors) {
    9    System.debug(error.errorCode + ': ' + error.message);
    10  }
    11}