1

I am writing a trigger in Change Data Capture (CDC) on an update of an event record (EventChangeEvent). I am getting the updated fields in the EventChangeEvent object record. Problem I am facing is how to tie the update field to the records which was just updated. If I am updating a single records I get the record id by doing header.getRecordIds[0] but when I am updating records in bulk there is no way to tie the updated fields to the actual record id. Here's the documentation of the message payload of the CDC event:

https://developer.salesforce.com/docs/atlas.en-us.change_data_capture.meta/change_data_capture/cdc_message_structure.htm

and

https://developer.salesforce.com/docs/atlas.en-us.change_data_capture.meta/change_data_capture/cdc_event_fields_header.htm

3

The change that's depicted in a Change Data Capture event applies to any and all records present in getRecordIds().

It's a distinctly different model than with regular Apex triggers, where the sObject's identity is primary. In CDC events, the primary payload is the change data itself, and the header tells you to which records the the change applies.

This behavior is described in Change Event Header Fields:

recordIds: One or more record IDs for the changed records. Typically, this field contains one record ID. But if the same change occurred in multiple records of the same object type during the same transaction, Salesforce groups the change notifications and sends one change event for all affected records. In this case, the recordIds field contains an array of record IDs for all records that have the same change

  • Thank you. It took a comment from you for me to wrap my head around it. – Json Bourne Shell Aug 12 at 0:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.