---
schema_version: "1"
id: 35ea5e55f7baaa2019b804122a8e5234a0f8e7c47fe11311755f643b875add80
title: Customize the Retail Order Save Process
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/retail_api/retail_order_apex_setup.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/retail_order_apex_setup.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: ea4594268c6bad9ee36d0761e7c918dd271f78538db4e7030a9199673a07b556
description: To customize the retail order save process, create a callable Apex class as a customization hook.
---
# 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](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/RE_order_class.htm "This Apex class provides programmatic access to the retail order sObject, and its related sObjects.").
    
    Here’s the Apex class structure.
    
    global class <Your Callable APEX Class> implements System.Callable {
    
      global Object call(String action, Map<String, Object> params) {
        // Get the RE\_Order instances from the arguments
        cgcloud.RE\_Order orderWrapper = (cgcloud.RE\_Order) params.get('order');
        // Get the Order SObject
        cgcloud\_\_Order\_\_c order = (cgcloud\_\_Order\_\_c) orderWrapper.getOrder().getRecord();
        // Retrieve your custom state sent to UI
        String payloadString = (String) params.get('customState');
    
        // Your custom logic goes here
        return null;
      }
    }
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.
    
    global class RetailOrderSaveCustomization implements System.Callable {
      public Object call(String m, Map<String, Object> params) {
        // Get the RE\_Order instance
        cgcloud.RE\_Order orderWrapper = (cgcloud.RE\_Order) params.get('order');
    
        // Get the Order\_\_c SObject
        cgcloud\_\_Order\_\_c order = (cgcloud\_\_Order\_\_c) orderWrapper.getOrder()
          .getRecord();
    
        /\*\*
         \* MyCustomSObject\_\_c is a custom object and it has a Custom\_\_c field.
         \* Use append method so that this new SObject will be created as part of the order save process.
         \*/
        MyCustomSObject\_\_c mySObject = new MyCustomSObject\_\_c();
        mySObject.Custom\_\_c = order.cgcloud\_\_Customer\_Order\_Id\_\_c;
        cgcloud.RE\_Order.Record myRecordWrapper = orderWrapper.append(mySObject);
    
        return null;
      }
    }
    
    For use cases related to the order save process customization, see [Retail Order Save Customization Use Cases](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/retail_order_apex_save_customization.htm "Here are the different Apex customization use cases for the retail order save process.").
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.