function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Pugalagiri JPugalagiri J 

Merged Capture Events - LastModifiedDate field in separate instance (Trigger.new)

I am currently working on change data capture and exploring merged capture events (i.,e mutiple update actions will be merged and available in single event) refer: https://developer.salesforce.com/docs/atlas.en-us.change_data_capture.meta/change_data_capture/cdc_subscribe_merged_events.htm

When testing merge events by updating 3 records with same fields, events are merged into 1 event but 1 event have separate parameter for actual field updated and lastmodifieddate. Is it expected behaviour of change capture event ?

Example: 
1, Updating Field Status in Object Account for 3 records using DML
2, Single event created and captured in trigger
3, Trigger.new is as below

(AccountChangeEvent
{
Id=1CDRcbppo9;
getChangeFeilds=(LastModifiedDate);
Sequence=1;
getRecordIds('00012HJKu','000HDyi78','00BHFDuu7')
},
AccountChangeEvent
{
Id=1XVRcpqqG9;
getChangeFeilds=(Status);
Sequence=1;
getRecordIds('00012HJKu','000HDyi78','00BHFDuu7')
}
)

But I am expecting as below,

(AccountChangeEvent
{
Id=1CDRcbppo9;
getChangeFeilds=(Status,LastModifiedDate);
Sequence=1;
getRecordIds('00012HJKu','000HDyi78','00BHFDuu7')
}
)

Is it the expected behaviour or bug ?


 
ShivankurShivankur (Salesforce Developers) 
Hi Pugalagiri,

I understand that you are not able to see Status,LastModifiedDate both together in the merged Change Events response.

As per standard documentation, the schema would look like as below example:
{
  "schema": "I8b-dYxvxs5wOtCBr4qsew",
  "payload": {
    "LastModifiedDate": "2021-01-20T22:33:10Z",
    "Industry": "Apparel",
    "ChangeEventHeader": {
        "commitNumber": 10708862594919,
        "commitUser": "005B0000006GudtIAC",
        "sequenceNumber": 1,
        "entityName": "Account",
        "changeType": "UPDATE",
        "changedFields": [
            "Industry",
            "LastModifiedDate"
        ],
        "changeOrigin": "com/salesforce/api/soap/51.0;client=devconsole",
        "transactionKey": "0003d969-c182-f926-e9fd-146339d7288c",
        "commitTimestamp": 1611181990000,
        "recordIds": [
            "001B000001LiHPKIA3",
            "001B000001Lw7SFIAZ",
            "001B000001Lw7SKIAZ"
        ]
    }
  },
  "event": {
    "replayId": 899
  }
}

Please also take note of Conversions That Generate a Change Event:
Reference: https://developer.salesforce.com/docs/atlas.en-us.change_data_capture.meta/change_data_capture/cdc_field_conversion_single_event.htm

A gap event is generated for all the affected records for some field conversions from Picklist. The change event header of the gap event message contains information about the records, including the record IDs and a change type of GAP_UPDATE.
Reference: https://developer.salesforce.com/docs/atlas.en-us.change_data_capture.meta/change_data_capture/cdc_field_conversion_gap_event.htm
https://developer.salesforce.com/docs/atlas.en-us.change_data_capture.meta/change_data_capture/cdc_field_conversion_no_events.htm

If you still see any discrepencies or not working as intended, its recommended to raise a case with Salesforce support to get it debugged to be reported to product teams to take care of as a bug.

Hope above information helps, Please mark as Best Answer so that it can help others in the future.

Thanks.
Pugalagiri JPugalagiri J
Thanks for your inputs, even in the example which you have shared LastModifiedDate and Industry are available in same instance of a trigger.
But for my case its not the same,

For my case LastModifiedDate and Industry are available in separate instance (i.e., its not as per the schema provided in the salesforce documentation)

Example shared below:

(AccountChangeEvent
{
Id=1CDRcbppo9;
getChangeFeilds=(LastModifiedDate);
Sequence=1;
getRecordIds('00012HJKu','000HDyi78','00BHFDuu7')
},
AccountChangeEvent
{
Id=1XVRcpqqG9;
getChangeFeilds=(Status);
Sequence=1;
getRecordIds('00012HJKu','000HDyi78','00BHFDuu7')
}
)

But I am expecting as below,

(AccountChangeEvent
{
Id=1CDRcbppo9;
getChangeFeilds=(Status,LastModifiedDate);
Sequence=1;
getRecordIds('00012HJKu','000HDyi78','00BHFDuu7')
}
)