Newer Version Available

This content describes an older version of this product. View Latest

Change Event Message Structure

A change event message contains header fields and record fields.

This event example shows the structure of the payload of an event message received in a Pub/Sub API client.

1{
2  "ChangeEventHeader": {
3    "entityName": "...",
4    "recordIds": [...],
5    "changeType": "   ",
6    "changeOrigin": "   ",
7    "transactionKey": "   ",
8    "sequenceNumber": ,
9    "commitTimestamp": ,
10    "commitNumber": ,
11    "commitUser": "   ",
12    "nulledFields": [...],
13    "diffFields": [...],
14    "changedFields": [...]
15  },
16  "field1": "...",
17  "field2": "...",
18  ...
19}

In a Pub/Sub API client, the received event message is in binary Apache Avro format. You can retrieve the schema, replay ID, and payload from the received event separately and decode the payload to obtain the ChangeEventHeader and record fields. This example shows the payload field only. For more information, see Pub/Sub API as a gRPC API in the Pub/Sub API documentation. Also, the received event in Pub/Sub API contains these ChangeEventHeader fields: nulledfields and diffFields.

Note

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.

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 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.

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 REST API that includes the schema ID sent in the event message:

1/vXX.X/event/eventSchema/<Schema_ID>?payloadFormat=COMPACT

Or 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.

Change Event Example in Pub/Sub API

This event message is sent for a new account in a Pub/Sub API client.

1{
2  "ChangeEventHeader": {
3    "entityName": "Account",
4    "recordIds": [
5      "0015f00002J9YYEAA3"
6    ],
7    "changeType": "CREATE",
8    "changeOrigin": "com/salesforce/api/soap/60.0;client=SfdcInternalAPI/",
9    "transactionKey": "0001ade9-3f74-0b99-dbc4-42e73424b774",
10    "sequenceNumber": 1,
11    "commitTimestamp": 1712693965000,
12    "commitNumber": 1082985383811,
13    "commitUser": "0055f000005mc66AAA",
14    "nulledFields": [],
15    "diffFields": [],
16    "changedFields": []
17  },
18  "Name": "Acme",
19  "Type": null,
20  "ParentId": null,
21  "BillingAddress": null,
22  "ShippingAddress": null,
23  "Phone": null,
24  "Fax": null,
25  "AccountNumber": null,
26  "Website": null,
27  "Sic": null,
28  "Industry": null,
29  "AnnualRevenue": null,
30  "NumberOfEmployees": null,
31  "Ownership": null,
32  "TickerSymbol": null,
33  "Description": "Sample account record.",
34  "Rating": null,
35  "Site": null,
36  "OwnerId": "0055f000005mc66AAA",
37  "CreatedDate": 1712693965000,
38  "CreatedById": "0055f000005mc66AAA",
39  "LastModifiedDate": 1712693965000,
40  "LastModifiedById": "0055f000005mc66AAA",
41  "Jigsaw": null,
42  "JigsawCompanyId": null,
43  "CleanStatus": "Pending",
44  "AccountSource": null,
45  "DunsNumber": null,
46  "Tradestyle": null,
47  "NaicsCode": null,
48  "NaicsDesc": null,
49  "YearStarted": null,
50  "SicDesc": null,
51  "DandbCompanyId": null,
52  "OperatingHoursId": null,
53  "CustomerPriority__c": null,
54  "SLA__c": null,
55  "Active__c": null,
56  "NumberofLocations__c": null,
57  "UpsellOpportunity__c": null,
58  "SLASerialNumber__c": null,
59  "SLAExpirationDate__c": null
60}