Newer Version Available

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

Subscribe to Change Events

You subscribe to change events with CometD or Apex triggers. CometD is a messaging library that enables listening to events through long polling and simulates push technology. Apex triggers for change events are similar to Apex triggers on platform events.

The Event Bus

Change events are based on platform events and share some of their characteristics. Change event messages are published to the event bus, where they are stored temporarily for three days. You can retrieve stored event messages from the event bus. Each event message contains the ReplayId field, which identifies the event in the stream and enables replaying the stream after a specific event. For more information, see Message Durability in the Streaming API Developer Guide.

Order of Events

The order of change events stored in the event bus corresponds to the order in which the transactions corresponding to the record changes are committed in Salesforce. If a transaction includes multiple changes, like a lead conversion, a change event is generated for each change with the same transactionKey but different sequenceNumber in the header. The sequenceNumber is the order of the change within the transaction. For efficiency, sometimes change events for one transaction are grouped into one event if the same change occurred in multiple records of the same object type during one second. For example, when an account field is updated to the same value across multiple records in a short time. In this case, the recordIds header field contains an array of record IDs for all records that have the same change. For more information, see Change Event Header Fields.

When Salesforce receives a change event, it assigns a replay ID value to it and persists it in the event bus. Subscribers receive change events from the event bus in the order of the replay ID.

User Permissions Required

The subscriber must have one or more of the following permissions depending on the subscription channel: View All Data, View All Users, and View All for an object. See Required Permissions for Change Events Received by CometD Subscribers.