Salesforce Real-time Events Using MuleSoft’s Salesforce Connector (Push Topic)

Salesforce Real-time Events Using MuleSoft’s Salesforce Connector (Push Topic)

Today I am going to discuss about the real-time event provided by Salesforce Streaming API. There are two types of real-time events in Streaming API which are supported in our MuleSoft’s Salesforce Connector. They are PushTopic and Change Data Capture. In this blog post, I am going to cover PushTopic. 

Description 

PushTopic Events are basically used to track the changes in Salesforce in real-time. It tracks when create, update, delete and undelete operation on a salesforce object, and fires an event when the changes occurred. To get this event trigger in your mule flow, first, there is the configuration you must do to subscribe to these events. 

 

Features: 

  • Subscribe via Apex Triggers 
  • Get field-level security 
  • Event data will be in Apex Trigger as a query 
  • Filter Subscriptions (subscribers) 
  • Record sharing support 
  • Can choose specific fields to retrieve when an event occurs 

 

    PushTopic Configuration: 

Create PushTopic in the Developer console. Event Notification is generated for updates that match the Query. 

  1.  Login to https://login.salesforce.com/ 
  2. Top right corner under the settings select the developer console
  3. Click Debug and Open Execute Anonymous Window
  4. In the Enter Apex Code window, paste in the following Apex code, and click execute
  5. The NotifyForOperationCreate, NotifyForOperationUpdate, NotifyForOperationDelete, and NotifyForOperationUndelete are set to true
  6. Save the push topic name, as we need to use that while configuring Salesforce Connector.
  7. Streaming API evaluates the records that are created, updated, deleted, undelete, and generates a notification if the record matches the PushTopic query
  8. In the Anypoint studio create a project and do salesforce configuration
  9. Use the PushTopic Query to subscription channel that corresponds to the change notification you want to receive. The channel name is case sensitive.
  10. In the General tab topic, you must specify the topic name (as shown above pic) which you want to subscribe to get the notifications when the object’s record is created or updated
  11. Run your application, when you create, update, delete and undelete changes of a salesforce record you will get the notification. 

If you observe the above apex code, in that, we have specified push topic name as ContactPushTopic.  In the Salesforce Connector property named Topic, you need to specify it here. Once you run the application, the Mule will create a salesforce session, which will contact this topic and subscribe to it. So, whenever any operation is done on contact, this flow will get triggered and we will get the response. 

Note: In the apex code, a property called NotifiedForFields, which specifies the Streaming API, what to retrieve. Supported values are ALL and REFERENCED 

  • ALL:  All the fields of the object will be retrieved when an operation is done on it 
  • REFERENCED: Only the fields in the query will be retrieved when an operation is done on it 

Conclusion:  

By Using PushTopic we will get real-time salesforce notifications when create, update, delete and undelete changes of a salesforce record, and fires an event when the changes occurred. Please stay tuned for blog Real-Time Event types Change Data Capture. 

I hope you got to learn something new from this blog. Please let me know your thoughts in the comments section below.

Leave a Reply