Message Durability
Event Bus
With API version 37.0 and later, events are published to the event bus. Subscribers retrieve events from a channel on the event bus, including past events that are stored temporarily. The event bus decouples event publishers from event subscribers.

Event Replay Process
Each event message is assigned an opaque ID contained in the ReplayId field. The ReplayId field value, which is populated by the system when the event is delivered to subscribers, refers to the position of the event in the event stream. Replay ID values aren’t guaranteed to be contiguous for consecutive events. A subscriber can store a replay ID value and use it on resubscription to retrieve events that are within the retention window. For example, a subscriber can retrieve missed events after a connection failure. Subscribers must not compute new replay IDs based on a stored replay ID to refer to other events in the stream.
To uniquely identify a platform event message, use the EventUuid system field and not the ReplayId field. The ReplayId field isn’t guaranteed to be unique when Salesforce maintenance activities occur, such as an org migration. The EventUuid field is always unique.
These examples show the contents of event messages with the replayId field. Even though the replayId fields in the examples contain numbers, they’re opaque fields. We recommend that you don’t assume that they always contain numbers. It’s best that you store the replayId values as bytes.
Platform event messages contain a replay ID when delivered to a CometD client. This JSON message shows the replayId field in the event object for the Low_Ink__e platform event.
{
"data": {
"schema": "dffQ2QLzDNHqwB8_sHMxdA",
"payload": {
"CreatedDate": "2023-04-09T18:31:40.517Z",
"CreatedById": "005D0000001cSZs",
"Printer_Model__c": "XZO-5",
"Serial_Number__c": "12345",
"Ink_Percentage__c": 0.2
},
"event": {
"EventUuid": "2ec0e371-1395-457f-9275-be1b527a72f7",
"replayId": 2112
}
},
"channel": "/event/Low_Ink__e"
}
This JSON message shows the replayId field in the event object for a Change Data Capture event.
{
"data": {
"schema": "IeRuaY6cbI_HsV8Rv1Mc5g",
"payload": {
"ChangeEventHeader": {
"entityName": "Account",
"recordIds": [
"<record_ID>"
],
"changeType": "CREATE",
"changeOrigin": "com.salesforce.core",
"transactionKey": "001b7375-0086-250e-e6ca-b99bc3a8b69f",
"sequenceNumber": 1,
"isTransactionEnd": true,
"commitTimestamp": 1501010206653,
"commitNumber": 92847272780,
"commitUser": "<User_ID>"
},
"Name": "Acme",
"Description": "Everyone is talking about the cloud. But what does it mean?",
"OwnerId": "<Owner_ID>",
"CreatedDate": "2017-07-25T19:16:44Z",
"CreatedById": "<User_ID>",
"LastModifiedDate": "2017-07-25T19:16:44Z",
"LastModifiedById": "<User_ID>"
},
"event": {
"replayId": 6421
}
},
"channel": "/data/ChangeEvents"
}
Replaying Events
A subscriber can choose which events to receive, such as all events within the retention window or starting after a particular event. The default is to receive only the new events sent after subscribing. Events outside the retention period are discarded.
This high-level diagram shows how event consumers can read a stream of events by using various replay options.
To replay events, use the Streaming API endpoint.
https://MyDomainName.my.salesforce.com/cometd/64.0/
// Register streaming extension
var replayExtension = new cometdReplayExtension();
replayExtension.setChannel(<Streaming Channel to Subscribe to>);
replayExtension.setReplay(<Event Replay Option>);
cometd.registerExtension('myReplayExtensionName', replayExtension);
After calling the setReplay() function on the extension, the events that the subscriber receives depend on the replay value parameter passed to setReplay().
After a client times out because it hasn’t reconnected within 40 seconds or a network failure has occurred, it attempts a new handshake request and reconnects. The replay extension saves the replay ID of the last message received and uses it when resubscribing. That way, the client receives only messages that were sent after the timeout and doesn’t receive duplicate messages that were sent earlier.
Code Samples
- Java Sample
- For a Java client sample that uses the CometD extension, see Example: Subscribe to and Replay Events Using a Java Client (EMP Connector).
- Lightning Component Sample
- For a sample that uses the empApi Lightning component, see Example: Subscribe to and Replay Events Using a Lightning Component.
- Visualforce Sample
- For a sample and code walkthrough that uses Visualforce and a CometD extension in JavaScript, see Example: Subscribe to and Replay Events Using a Visualforce Page.