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
Flows are used to create platform events, the
modifiedFields section of the payload contains values, because
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 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, 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, click > > , and then in the right pane, deactivate the active Flow for Service Board real-time sync for the Work Order object.
2. In the left pane, click > > , and then in the list view, click Work Order
3. On the object page, in the left pane, click Triggers, and then in the right pane, click New.
4. On the Apex Trigger Input page, implement Apex code.
Sample Work Order Trigger
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);
}