Order Change Manager

Order Change Manager maintains the integrity of orders in the Salesforce database. It allows Salesforce users to work with multiple order carts on different tabs simultaneously, while for CT Mobile users, it tracks all changes to the order cart and performs their successful submission to the Salesforce database.

Overview

Order Change Manager is used for:

  • Ensuring the integrity of orders saved in Salesforce.

  • Loading all required CT Orders records with the specified conditions to the CT Mobile app.

  • Handling conflicts of simultaneous editing of the same order in Salesforce and CT Mobile.

  • Allows Salesforce users to simultaneously work with multiple order carts on different tabs. Go to the article to view the required user permissions.

Order Change Manager uses a public method for Order Lightning Web interface in Salesforce and a custom REST API for CT Mobile and controls data integrity the following objects:

  • CT Order

  • Order Line Item

  • Delivery

  • Delivery Line Item

  • Calculated Discount

Keeping Data Up-to-Date in Orders

When a mobile user performs a synchronization, orders that are available for this user will be downloaded on the mobile device along with all related records. If a user made changes to the order cart:

  1. REST API creates package(s) with changes for a specific Order record if any related records of that order have been changed, created, or deleted.

    1. Each package contains no more than 200 records for a particular order.

    2. If the total number of transferred object records exceeds 200 records, the order will be split into several packages, which are formed according to that order:

      1. Order

      2. Order Line Item, Delivery

      3. Delivery Line Item, Calculated Discount

    3. Each Order record is presented as a JSON file (flat list) in package(s).

      To learn more about JSON keys and view examples, refer to Order Change Manager: JSON Examples and Keys.
  2. During the synchronization, REST API sends package(s) with changes to the records of the following CT Orders objects to a designated endpoint: {{Salesforce_instance_url}}/services/apexrest/ChangeManager. The standard CT Mobile functionality for iOS users, such as Sync Recovery, Conflict Manager, and Online Records Fetching, does not apply to those CT Orders objects.

  3. On the Salesforce side, the system creates an Order Change Manager record for the particular Order and fills it out with the received JSONs. If a previous Order Change Manager record is found, it will be deleted. For more information, refer to Order Change Manager Field Reference.

  4. The Order Change Manager checks SOQL queries received from CT Mobile. If the query contains a mobile temporary record ID, Order Change Manager checks if there is a record with the same value in the Reference Id field in Salesforce. If such a record is found, Order Change Manager updates it. Otherwise, Order Change Manager creates a new record.

  5. REST API gets a response from Salesforce:

    • records are successfully saved;

    • records are successfully copied;

    • an error occurred.

  6. When a user closes the order cart, finalizes, or completes the order in Salesforce, the corresponding Order Change Manager record is deleted.

Order Deduplication Logic

The deduplication logic allows you to handle conflicts and keep data consistency of created orders and related object records. For this purpose, the orders__ReferenceId__c field is created on the following objects:

  • Order

  • Order Line Item

  • Delivery

  • Delivery Line Item

  • Calculated Discount

A mobile user should have permission to edit the Reference Id field on all the following objects.

The Reference Id field stores the pair of record ID and user ID.

  • If the record has not yet been transferred from CT Mobile, the field contains the mobile temporary record ID and the user identifier.

    For example, a06-AF3AA67B-EA24-4DAB-9C8A-9B70357DAB830055J000001L7aTQAS, where a06-AF3AA67B-EA24-4DAB-9C8A-9B70357DAB83 is the temporary record ID and 0055J000001L7aTQAS is the user identifier.

  • If the record was transferred to Salesforce, the field contains the Salesforce record ID and the user identifier.

    For example, a0g5w00000EQJi1AAH0055J000001L7aTQAS, where a0g5w00000EQJi1AAH is the Salesforce record ID and 0055J000001L7aTQAS is the user identifier.

Deduplication Logic for the Finalized Order

Sometimes, there are situations when the same order has different statuses on the mobile device and in Salesforce because the mobile user did not perform the fast synchronization. Use the additional option to control whether to create a duplicate of the finalized order with all related records in Salesforce, or update it if a mobile user made changes to this order. For more information about the order stages, refer to Order Stages.

For example, an order was downloaded to a mobile device and then finalized in Salesforce. If, after finishing the order in Salesforce, the mobile user did not run synchronization and made changes to the same order in CT Mobile, a duplicate order will be created with all related records in Salesforce during the next synchronization.

The administrator can change the default behavior using the Turn Off Closed Orders Duplication checkbox on the appropriate Sales Organization record.

  • By default, the checkbox is disabled. A duplicate of the mobile order will be created with all related records in Salesforce when a mobile user edits this record on the mobile device. This logic does not affect orders on the On-Hold stage in Salesforce.

  • When the checkbox is selected, the finalized order is updated in Salesforce if a mobile user has edited it in CT Mobile.

    Enabling the option can cause conflicts in the case when there is the custom business logic to send the finalized orders to ERP from Salesforce.
``