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:




1 Answer 1


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. Aug 12, 2019 at 0:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .