Streaming API in Salesforce 

The 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 Asynchronous in Nature.

Data Format is JSON.

When to use Streaming API

              Use Streaming API to receive near-real-time streams of data that are based on changes in salesforce records or custom payloads. If a salesforce record changes,salesforce publishes notifications when the changes occur.

Types of Event Available

  • Push Topic Event.
  • Change Data Capture Event.

Let us Discuss One by One with Example

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

Click confirm Insert.

Select the  created Push Topic Name in the dropdown  and then Subscribe.

It will show connection Established Successful in Json.

In the dropdown,select Queries and click streaming pushtopics.

This is the SOQL Query  we used to implement the pushTopic 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 creation of a new record,updates to an exsisting record,deletion of a record,undeletion of a record.
  • The objects can be selected through UI, for publishing events.
  • The CDC supports for 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.

Leave A Comment

All fields marked with an asterisk (*) are required