Streaming API in Salesforce
- Salesforce Streaming API is used when you need to keep your external source in sync with the Salesforce data with PushTopic events and Change Data Capture events.
- Streaming API uses Bayeux Protocol and is Asynchronous in Nature.
- Data format is JSON.
When to use Streaming API
Use Streaming API to receive near-real-time data streams based on changes in salesforce records or custom payloads. If salesforce records changes, salesforce publishes notifications when the changes occur.
Types of Events Available
- Push Topic Event.
- Change Data Capture Event.
Push Topic Event
Receive changes to salesforce records based on a SOQL Query that you define. The notifications include only the fields that you specify in the SOQL query.
Push Topic Implementation
Select PushTopic from object type and click next
Click confirm insert
Select the created push topic name in the dropdown and then subscribe.
It will show the connection Established Successfully in JSON.
In the dropdown, select queries and click streaming push topics.
This is the SOQL Query we used to implement the push topic Event
SELECT Id, StageName , CloseDate from Opportunity where CloseDate=TODAY
This is the created record based on the Query.
Change Data Capture Event
- Receive Changes to salesforce records with all changed fields. Change data capture supports more standard objects than pushTopic Events and provides more Features.
- Changes include the creation of a new record, updates to an existing record, deletion of a record, and undeletion of a record.
- The objects can be selected through UI, for publishing events.
- The CDC supports all custom and standard objects.
- The channel for subscription for standard object /data/<Standard_object_Name>
- Example: /data/ContactChangeEvent
- The channel for subscription for custom Object /data/<Custom_object_Name>__ChangeEvent
- Example: /data/Employee__ChangeEvent
Implementation of CDC
In quick find, search Change Data Capture
Select objects from available entities to standard entities click save.
In queries dropdown, select streaming push topics
In Subscriptions, Enter /data/ContactChangeEvent.
Click subscribe.
The contact record is created.
And the same record is updated.