Newer Version Available

This content describes an older version of this product. View Latest

Customize the Retail Order Save Process

To customize the retail order save process, create a callable Apex class as a customization hook.
  1. Log in to your Salesforce org, and go to Developer Console.
  2. Create a global Apex class that implements the System.Callable interface.
  3. Override the global call method that has these parameters.
    • action: String. The behavior for the method to exhibit.
    • params: Map<String,Object>. Arguments to be used by the specified action. The object is of type RE_Order. The RE_Order class exposes methods to access the retail order sObject. For a list of all the exposed methods, see RE_Order Class Reference.

    Here’s the Apex class structure.

    1global class <Your Callable APEX Class> implements System.Callable {
    2
    3  global Object call(String action, Map<String, Object> params) {
    4    // Get the RE_Order instances from the arguments
    5    cgcloud.RE_Order orderWrapper = (cgcloud.RE_Order) params.get('order');
    6    // Get the Order SObject
    7    cgcloud__Order__c order = (cgcloud__Order__c) orderWrapper.getOrder().getRecord();
    8    // Retrieve your custom state sent to UI
    9    String payloadString = (String) params.get('customState');
    10
    11    // Your custom logic goes here
    12    return null;
    13  }
    14}
  4. To modify the order fields, use the methods exposed by the RE_Order class.
    Add your customizations in the Apex class to:
    • Create retail order records.
    • Modify and delete existing retail order records.
    Here’s a sample Apex class that adds a custom sObject record during the order save process.
    1global class RetailOrderSaveCustomization implements System.Callable {
    2  public Object call(String m, Map<String, Object> params) {
    3    // Get the RE_Order instance
    4    cgcloud.RE_Order orderWrapper = (cgcloud.RE_Order) params.get('order');
    5
    6    // Get the Order__c SObject
    7    cgcloud__Order__c order = (cgcloud__Order__c) orderWrapper.getOrder()
    8      .getRecord();
    9
    10    /**
    11     * MyCustomSObject__c is a custom object and it has a Custom__c field.
    12     * Use append method so that this new SObject will be created as part of the order save process.
    13     */
    14    MyCustomSObject__c mySObject = new MyCustomSObject__c();
    15    mySObject.Custom__c = order.cgcloud__Customer_Order_Id__c;
    16    cgcloud.RE_Order.Record myRecordWrapper = orderWrapper.append(mySObject);
    17
    18    return null;
    19  }
    20}
    For use cases related to the order save process customization, see Retail Order Save Customization Use Cases.
  5. From Setup, in the Quick Find box, enter Custom Metadata Types, and then expand Custom Metadata Types.
  6. Click Manage Records on the CGCloud Process Customization row.
  7. Click New, fill in these details, and then save your work.
    • Label: RE_Order_Save
    • DeveloperName: RE_Order_Save
    • Class: <Your Callable APEX Class>
    • Method: save
    • Enabled: Select the checkbox
The Apex customization hook is enabled. When a retail order is saved, the call method modifies the saved order based on your custom logic.