1

I'm subscribing to a change data capture event stream via an Apex trigger. It appears there can be multiple record IDs associated with each change event. Does this mean that all the changes on these records are identical, including SystemModstamp?

For reference: https://developer.salesforce.com/docs/atlas.en-us.change_data_capture.meta/change_data_capture/cdc_trigger_example.htm

Example from the start of the trigger:

trigger CaseChangeEventTrigger on CaseChangeEvent (after insert) {
 
    List<CaseChangeEvent> changes = Trigger.new;
    
    Set<String> caseIds = new Set<String>();
    
    for (CaseChangeEvent change : changes) {
        // Get all Record Ids for this change and add to the set
        List<String> recordIds = change.ChangeEventHeader.getRecordIds();
        caseIds.addAll(recordIds);   // Why is there more than one recordId / change???
    }

....

1 Answer 1

0

Correct. Per the documentation:

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

This could happen for a number of reasons, most likely audit fields such as LastModifiedBy, LastModifiedDate, SystemModStamp, etc, as well as changes a user or API makes to set many records to the same value, perhaps from something like a Mass Assign Ownership button or script.

You must log in to answer this question.

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