GraphRequest Class

Contains constructors and properties to set the graph ID and a list of records to be ingested. The list of records is specified in a key-value map format that contains the field values of an order.

Namespace 

CommerceOrders

Example 

Create the list of records to be ingested by using these steps.

  • 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// Process any error, if exists
    5if (!result.success) {
    6  List<ConnectApi.PlaceOrderErrorResponse> errors = result.responseError;
    7  for (ConnectApi.PlaceOrderErrorResponse error : errors) {
    8    System.debug(error.errorCode + ': ' + error.message);
    9  }
    10}
  • GraphRequest Constructors

    Learn more about the available constructors with the GraphRequest class.

  • GraphRequest Properties

    Learn more about the available properties with the GraphRequest class.

GraphRequest Constructors 

Learn more about the available constructors with the GraphRequest class.

The GraphRequest class includes these constructors.

GraphRequest(graphId, records) 

Creates an instance of the GraphRequest class to assign the graph ID and a list of records to be ingested.

Signature 

public GraphRequest(String graphId, List<commerceorders.RecordWithReferenceRequest> records)

Parameters 

graphId

Type: String

ID of the graph.

records

Type: List<commerceorders.RecordWithReferenceRequest>

List of records to be ingested.

GraphRequest Properties 

Learn more about the available properties with the GraphRequest class.

The GraphRequest class includes these properties.

  • graphId

    Set the graphId property to assign the ID value of the graph.

graphId 

Set the graphId property to assign the ID value of the graph.

Signature 

public String graphId {get; set;}

Property Value 

Type: String