As part of your m3ter Connector for Salesforce managed package and as a alternative to manually syncing your Salesforce data with your m3ter data, you can set up and configure an Invocable Action (IA) and enable event-driven automated syncing of data.
The Sync to m3ter Invocable Action provides a mechanism for initiating synchronization between Salesforce and m3ter:
Allows for easy integration with Salesforce Flows and Apex, enabling automated sync processes based on a customer business process or automation needs.
Extends the current manual sync functionality and leverages the same metadata / configuration driven approach by adding a layer of extensibility, namely via a new IA named Sync To m3ter
This topic explains how to set up and work with the Sync to m3ter IA feature for your m3ter Connector managed package, and provides essential reference information on its details, design, and operational constraints:
Important!
Note on Usage: The Sync to m3ter Invocable Action is designed for low-volume, event-driven synchronization. It is not intended for high-volume batch processing of hundreds of records daily. The primary goal is to automate individual sync processes, eliminating the need for manual user intervention while maintaining system performance and stability.
Check Version. The Sync to m3ter Invocable Action feature is only available in version 0.4 and above of the m3ter Connector for Salesforce managed package. See m3ter Connector for Salesforce - Changelog for details on how to check your current installed version.
There are two ways you can implement Sync to m3ter IA feature for use with your managed package:
Flow
APEX
The following diagram highlights the key settings when implementing with Flow using Recorded Trigger Flows:
You must perform three configuration tasks to ensure that the Action performs as expected when using Record Triggered Flows:
1. To enable Run Asynchronously, you must select the checkbox for:
Include a Run Asynchronously path to access an external system after the original transaction for the triggering record is successfully committed.
2. In the options for When to Run the Flow for Updated Records, you must select:
Only when a record is updated to meet the condition requirements.
3. You must add the Action to the Run Asynchronously path.
For implementing with APEX, the following is required and contains explanatory comments:
1// Create a new sync request2m3.SyncToM3terService.M3terSyncRequest req = new m3.SyncToM3terService.M3terSyncRequest();3req.parentRecordId = '006S900000795MMIAY'; // Replace with an actual Salesforce ID45// Call the invocable action6List<m3.SyncToM3terService.M3terSyncResult> results = m3.SyncToM3terService.syncToM3ter(7new List<m3.SyncToM3terService.M3terSyncRequest>{req}8);910// Process the results11if (!results.isEmpty()) {12m3.SyncToM3terService.M3terSyncResult result = results[0];1314System.debug('Overall Sync Success: ' + result.success);15System.debug('Sync Status: ' + result.syncStatus);16System.debug('Sync Message: ' + result.message);1718// Output concatenated results19System.debug('Concatenated Results:\n' + result.concatenatedResults);2021// Process individual object results22for (m3.SyncToM3terService.M3terSyncObjectResult objResult : result.objectResults) {23System.debug('Object: ' + objResult.objectName +24', Success: ' + objResult.success +25', Message: ' + objResult.message +26', Salesforce ID: ' + objResult.salesforceId);27}28} else {29System.debug('No results returned from sync operation.');30}31
1. Success = True, Sync Status = Completed:
15:52:39.49 (2279271858)|USER_DEBUG|[12]|DEBUG|Overall Sync Success:
true
15:52:39.49 (2279288498)|USER_DEBUG|[13]|DEBUG|Sync Status: Complete
15:52:39.49 (2279300703)|USER_DEBUG|[14]|DEBUG|Sync Message: Sync process completed successfully
15:52:39.49 (2279312987)|USER_DEBUG|[17]|DEBUG|Concatenated Results:
Object: Account, Success: true
, Message: m3ter Identifier: d82738f3-d1d7-4a13-94a2-757658d64948, Salesforce ID: 001S900000RzsIUIAZ
Object: Contract, Success: true
, Message: m3ter Identifier: e383ee1c-01e7-4f56-a220-cbf4888bd9ec, Salesforce ID: 006S900000795MNIAY
Object: Commitment, Success: true
, Message: m3ter Identifier: acc4483e-f74c-4fb2-80ed-219480892a90, Salesforce ID: 006S900000795MNIAY
Object: Plan, Success: true
, Message:m3ter Identifier: b22233fe-5d97-4961-a3e8-24e97df0fd45, Salesforce ID: 00kS9000001Nxy5IAC
Object: AccountPlan, Success: true
, Message: m3ter Identifier: b22233fe-5d97-4961-a3e8-24e97df0fd45, Salesforce ID: 00kS9000001Nxy5IAC
2. Success = False, Sync Status = Partial Success:
15:29:01.57 (2557064317)|USER_DEBUG|[12]|DEBUG|Overall Sync Success:
false
15:29:01.57 (2557081586)|USER_DEBUG|[13]|DEBUG|Sync Status: Partial Success
15:29:01.57 (2557093491)|USER_DEBUG|[14]|DEBUG|Sync Message: Sync process completed successfully
15:29:01.57 (2557105264)|USER_DEBUG|[17]|DEBUG|Concatenated Results:
Object: Account, Success: true
, Message: m3ter Identifier: d82738f3-d1d7-4a13-94a2-757658d64948, Salesforce ID: 001S900000RzsIUIAZ
Object: Contract, Success: true
, Message: m3ter Identifier: 83df45e7-78ea-4211-8d12-6220b7c7ca86, Salesforce ID: 006S900000795MNIAY
Object: Commitment, Success: false
, Message: Commitment would overlap with existing Commitment 293b2bca-fa87-4036-9a0b-e0f1d3cd8c9e, Salesforce ID: 006S900000795MNIAY
Object: Plan, Success: false
, Message: The object plans
for
the record 00kS9000001Nxy5IAC was flagged to not sync., Salesforce ID: 00kS9000001Nxy5IAC
Object: Pricing, Success: false
, Message: The object pricings
for
the record 00kS9000001Nxy5IAC was flagged to not sync., Salesforce ID: 00kS9000001Nxy5IAC
Object: AccountPlan, Success: false
, Message: AccountPlan would overlap with AccountPlan 544ecdae-54a5-4654-b0fb-b503a7ed58b2
for
the same product 21e063b6-2350-4add-a028-3e6ad5b233ed, Salesforce ID: 00kS9000001Nxy5IAC
This section provides important reference information if you choose to implement the Sync to m3ter IA feature.
Field Name | Purpose |
---|---|
INPUT | |
Parent Record ID | Salesforce ID of the parent record that initiates the sync process. (Required) |
OUTPUT | |
Success | Boolean indicating if the entire sync process was successful. True if all object results are success. False if any object result is false. |
Sync Status | String describing the overall status. For example - "Completed", "Partial Success", "Failed". Completed if all object results are success. Partial Success if any object result is false. Failed if any system exceptions are thrown. |
Message | Detailed message about the overall sync result. For example - "Sync process completed successfully" or "Sync process failed: [exceptionMessage]". |
Object Results | Map of object names to lists of individual sync results, providing granular details for each synced record. |
Concatenated Results | A string representation of all object results. Note: This string is expected to be longer than 255 chars. |
Field Name | Purpose |
---|---|
Object Name | Name of the Salesforce/m3ter object being synced. |
Success | Boolean indicating if this particular object sync was successful. |
Message | Detailed message about this object's sync result. |
Salesforce ID | The Salesforce ID of the synced record. |
Some operational safeguards and design constraints are built into the Sync to m3ter IA. Please review this section before implementing and running the feature.
To ensure predictable behavior and prevents resource exhaustion:
The Action is explicitly designed to process only one record at a time.
Multiple record requests will result in a Failed status with appropriate error message.
Validation checks:
Performs existence check on the parent record before initiating sync.
Returns specific error statuses for:
Invalid/null record IDs.
Non-existent records.
Record access issues.
Three status codes are given:
Completed: All objects synced successful.
Partial Success: Some objects synced successfully, others failed.
Failed: System-level failures (CPU limits, validation errors, and so on).
Given the action will perform a number of API callouts to m3ter, you must ensure that it is called from a separate transaction to avoid provoking the following error:
"You have uncommitted work pending. Please commit or rollback before calling out"
This is a common Salesforce error related to transaction management and external callouts.
This error is particularly relevant to the Sync to m3ter Invocable Action because:
Flows: If the action is not set to run asynchronously, and there are any DML operations before it in the flow, you will encounter this error.
Apex: If you try to call the action directly after performing DML operations in the same transaction, you will get this error.
To avoid this error:
Flows: Always use the "Run Asynchronously" option for the Sync to m3ter action.
Apex: Use the @future(callout=true)
method. This ensures the callout happens in a separate transaction.
Login to the Support portal for additional help and to send questions to our Support team.