Customizing Work Order Platform Event Payloads
During Salesforce-to-Service Board real-time sync, only the fields specified in the modifiedFields section of the platform event payload for Salesforce Work Order updates are synchronized. In cases where the modifiedFields section of the payload is null, all fields specified in the fields section are synchronized. The values in the modifiedFields section of the payload are defined in the SB_WorkOrder_1 trigger, which is included in Service Board Extension SVMXSB release packages. When Process Builders or Flows are used to create platform events, the modifiedFields section of the payload contains values, because Process Builder and Flow execution takes place after triggers are executed. For further details, see Triggers and Order of Execution in the Salesforce Apex Developer Guide.
Salesforce does not guarantee the execution order of multiple triggers. In cases where custom triggers are defined to create platform events for Salesforce Work Orders instead of Process Builders or Flows, platform event creation trigger execution can sometimes take place before modifiedFields value-definition trigger execution. If this occurs, the modifiedFields section of the payload might be null, and all fields listed in the fields section might not be properly synchronized. To address this issue in Service Board tenants with release version packages SVMXSB 24.1 and later, you can call the SVMX.SB_ProcessBuilderHelper.createCollectionOfModifiedFields API before you implement platform event creation in the custom trigger.
To customize Work Order platform event payloads:
1. In Salesforce, on the Setup page, in the left pane, in the Platform Tools section, expand the Process Automation node, and then in the right pane, select and deactivate the active Flow or Process Builder for Service Board real-time sync for the Work Order object.
2. In the left pane, in the Platform Tools section, expand the Objects and Fields node, and then click Object Manager.
3. Click the Work Order object, and then on the object page, in the left pane, click Triggers.
4. In the right pane, click New, and then on the Apex Trigger Input page, implement Apex code.
trigger Sample_WorkOrder_Trigger on SVMXC__Service_Order__c (after update) {
SVMXSB.SB_ProcessBuilderHelper.createCollectionOfModifiedFields('SVMXC__Service_Order__c', trigger.old[0], trigger.new[0]);
List<SVMXSB.SB_ProcessBuilderHelper.ProcessBuilderParams> lstParams = new List<SVMXSB.SB_ProcessBuilderHelper.ProcessBuilderParams>();

SVMXSB.SB_ProcessBuilderHelper.ProcessBuilderParams params = new SVMXSB.SB_ProcessBuilderHelper.ProcessBuilderParams();
params.objectName = 'SVMXC__Service_Order__c';
params.recordId = trigger.new[0].Id;
params.eventName = 'update_job';

lstParams.add(params);
SVMXSB.SB_ProcessBuilderHelper.preparePlatformEvent(lstParams);

}
For more information:
Was this helpful?