Replay Events with Durable PushTopic Streaming (Generally Available)

You can now replay PushTopic-based streaming events! Salesforce stores events for 24 hours, so you can retrieve stored events during that window. This release, we expanded support of durable streaming to include PushTopic events, in addition to generic events.

The Streaming API event framework decouples event producers from event consumers. As a result, a subscriber can retrieve events at any time and isn’t restricted to listening to events at the time they’re sent.

Single Endpoint

Use the Streaming API endpoint to replay event notifications for durable PushTopic events. This endpoint also applies to durable generic events.



Durable streaming is supported at this endpoint starting with API version 37.0. If you’re using Durable Generic Streaming in version 36.0, we recommend that you upgrade to version 37.0 and use this endpoint instead of https://Salesforce_Instance/cometd/replay/36.0/.

Event Numbering

Each broadcasted event is assigned a numeric ID. IDs are incremented and not guaranteed to be contiguous for consecutive events. Each ID is guaranteed to be higher than the ID of the previous event. For example, the event following the event with ID 999 can have an ID of 1,025. The ID is unique for the org and the channel. The IDs of deleted events aren’t reused.

The ID is added in the replayId field of the notification message. For example, this JSON message shows the replayId field in the event object for a PushTopic event.



The time format of the createdDate field value has changed to make it consistent with the time format used in the Salesforce app. The time portion now ends with a Z suffix instead of +0000. Both suffixes denote a UTC time zone.

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 24-hour retention period are discarded.

This high-level diagram shows how event consumers can read a stream of events by using various replay options.

Diagram showing a stream of events with replay options
Table 1. Replay Options
Replay Option Description
Replay ID Subscriber receives all events after the event specified by its replayId value.
-1 Subscriber receives new events that are broadcast after the client subscribes.
-2 Subscriber receives all events, including past events that are within the 24-hour retention window and new events sent after subscription.

CometD Extension

The replay mechanism is implemented in a Salesforce-provided CometD extension. A sample extension is provided in JavaScript and another in Java. For example, you can register the extension as follows in JavaScript.
// Register streaming extension
var replayExtension = new cometdReplayExtension();
replayExtension.setChannel(<Streaming Channel to Subscribe to>);
replayExtension.setReplay(<Event Replay Option>);
cometd.registerExtension('myReplayExtensionName', replayExtension);

For a Visualforce sample that uses the CometD extension in JavaScript, see the Salesforce Durable Streaming Demo on GitHub. A walkthrough of this sample is provided in the Summer ’16 version of the Streaming API Developer Guide.

For CometD client extensions to replay events in Java and JavaScript, see