Newer Version Available
Change Event Message Structure
This event example is an event message received in a CometD client.
1{
2 "schema": "<schema_ID>",
3 "payload": {
4 "ChangeEventHeader": {
5 "entityName": "...",
6 "recordIds": "...",
7 "changeType": "...",
8 "changeOrigin": "...",
9 "transactionKey": "...",
10 "sequenceNumber": "...",
11 "commitTimestamp": "...",
12 "commitUser": "...",
13 "commitNumber": "...",
14 "changedFields": [...]
15 },
16 "field1": "...",
17 "field2": "...",
18 . . .
19 },
20 "event": {
21 "replayId": <replayID>
22 }
23}Change Event Fields
The fields that a change event can include correspond to the fields on the associated parent Salesforce object, with a few exceptions. For example, AccountChangeEvent fields correspond to the fields on Account.
The fields that a change event doesn’t include are:
- The IsDeleted system field.
- The SystemModStamp system field.
- Any field whose value isn’t on the record and is derived from another record or from a formula, except roll-up summary fields, which are included. Examples are formula fields. Examples of fields with derived values include LastActivityDate and PhotoUrl.
Each change event also contains header fields. The header fields are included inside the ChangeEventHeader field. They contain information about the event, such as whether the change was an update or delete and the name of the object, like Account.
In addition to the event payload, the event schema ID is included in the schema field. Also included is the event-specific field, replayId, which is used for retrieving past events.
API Version and Event Schema
When you subscribe to change events, the subscription uses the latest API version regardless of the API version that the client uses. The event messages received reflect the latest field definitions of the corresponding Salesforce object. When the object schema changes, such as when a field is added or a field type is changed, the schema ID changes. The change event contains the new schema ID in the schema field.
You can get the event schema through REST API or Pub/Sub API.
If using a CometD client, get the event schema with REST API. To get the full schema of a change event message, make a GET request to the REST API that includes the schema ID sent in the event message:
1/vXX.X/event/eventSchema/<Schema_ID>?payloadFormat=COMPACTOr make a GET request to this resource:
1/vXX.X/sobjects/<EventName>/eventSchema?payloadFormat=COMPACT<EventName> is the name of a change event, such as AccountChangeEvent.
The event schema REST API resources return the schema ID in the uuid field. To compare the schema with a previous version, retrieve the schema with a previous schema ID and the current schema ID.
The event schema REST API resources are also used for platform events. For more information, see Platform Event Schema by Event Name and Platform Event Schema by Schema ID in the REST API Developer Guide.
If using Pub/Sub API to subscribe to events, get the event schema with the GetSchema RPC method.
1rpc GetSchema (SchemaRequest) returns (SchemaInfo);For more information, see GetSchema RPC Method in the Pub/Sub API Developer Guide.
Change Event Example
The following event is sent for a new account in a CometD client.
1{
2 "schema": "I8b-dYxvxs5wOtCBr4qsew",
3 "payload": {
4 "ChangeEventHeader": {
5 "entityName": "Account",
6 "changeType": "CREATE",
7 "changedFields": [],
8 "changeOrigin": "com/salesforce/api/soap/47.0;client=SfdcInternalAPI/",
9 "transactionKey": "000177a7-c079-6e50-73af-5af790992cc1",
10 "sequenceNumber": 1,
11 "commitTimestamp": 1564443438000,
12 "commitNumber": 74523894988,
13 "commitUser": "<User_ID>",
14 "recordIds": [
15 "<record_ID>"
16 ]
17 },
18 "Name": "Acme",
19 "Description": "Everyone is talking about the cloud. But what does it mean?",
20 "OwnerId": "<Owner_ID>",
21 "CreatedDate": "2019-07-29T23:37:18.000Z",
22 "CreatedById": "<User_ID>",
23 "LastModifiedDate": "2019-07-29T23:37:18.000Z",
24 "LastModifiedById": "<User_ID>",
25 },
26 "event": {
27 "replayId": 10
28 }
29}For more change event examples received in a CometD client, see Subscribe to an Event Channel in the Change Data Capture Basics Trailhead module.