In the continuously evolving digital world, organisations are accumulating exponentially larger volumes of customer data, and it often becomes fragmented, duplicated, inconsistent and out-of-date as it travels across different systems and users. With Salesforce CRM being the single source of truth for many organisations, it is important to ensure the accuracy and reliability of customer data, not only within Salesforce but within every system that holds customer information.
In this article we will look in detail at how a customer-related event that is created or updated in Salesforce CRM, is captured, processed, and synchronised with other business systems of the organisation. We will cover the following in detail:
What is Salesforce CRM?
Salesforce is a leading enterprise SaaS platform and CRM (Customer Relationship Management) and is one of the core capabilities that Salesforce offers. It can manage all the customer interactions of an organization through different media, like phone calls, site email enquiries, communities, as well as social media. Salesforce handles all customer relationships, by focusing on sales, marketing and support processes.
What is a Streaming API and why is it useful?
Tracking data changes in Salesforce is especially useful when you have business data stored in a system external to Salesforce. You can use a Streaming API to keep your external source in sync with your Salesforce data with change data capture events and PushTopic events. Also, Streaming APIs let you process business logic in an external system in response to data changes in Salesforce. In this article we will cover PushTopics.
What is a PushTopic?
A PushTopic is an sObject (Salesforce Object) that contains the criteria of events you want to listen to, such as data changes for a particular object. You define the criteria as an SOQL query in the PushTopic and specify the record operations to notify on (create, update, delete, and undelete).
Use case
In this section, we will look in detail at creating a PushTopic to capture changes on an Account (Salesforce Object) and processing the events using Mule.
1. Steps to create a PushTopic in Salesforce
These instructions assume that you have a Salesforce Org created with access to the Account object.
PushTopic PushTopic = new PushTopic();
PushTopic.Name = 'AllAccounts';
PushTopic.Query = 'SELECT Id,FirstName,LastName,Name,Salutation,Phone From Account’;
PushTopic.ApiVersion = 51.0;
PushTopic.NotifyForOperationCreate = true;
PushTopic.NotifyForOperationUpdate = true;
PushTopic.NotifyForOperationUndelete = false;
PushTopic.NotifyForOperationDelete = false;
PushTopic.NotifyForFields = 'All';
insert PushTopic;
We have successfully created a PushTopic on Account object.
2. Subscribing to the Push Topic
Subscribe to the PushTopic that we just created to see the activity when Accounts are created or updated.
Below are the steps to subscribe to a PushTopic to view the events:
3. Processing the event message using MuleSoft
Now that we have our PushTopic capturing updates on Account, let’s look at processing the event using MuleSoft
Below are the steps required to create a listener in Mule 4:
<dependency>
<groupId>com.mulesoft.connectors</groupId>
<artifactId>mule-salesforce-connector</artifactId>
<version>10.12.1</version>
<classifier>mule-plugin</classifier>
</dependency>
<salesforce:sfdc-config name="Salesforce_Config" doc:name="Salesforce Config" doc:id="a7fb8b33-ed70-4f85-b8f6-ad7af7f395f4" >
<salesforce:basic-connection username="username" password="password" securityToken="token" />
</salesforce:sfdc-config>
<salesforce:replay-topic-listener topic="AllAccounts" replayOption="ONLY_NEW" doc:name="replay-sfdc-customer-topic-listener" doc:id="0995d776-1a15-42c1-8b98-451a01060db0" config-ref="Salesforce_Config"/>
The Mule application is now ready to be started/deployed.
In this article, we have covered creating a PushTopic on Accounts object in Salesforce and processing the event messages using Mule 4.
More information on Salesforce PushTopics can be found here
More information on Mule Salesforce Replay Topic Listener Component can be found here
If you would like to find out more about how you can leverage MuleSoft to enhance your Salesforce capability and drive growth, we can help. Give us a call or email us at Salesforce@coforge.com.
Other useful links:
Salesforce Clouds and Solutions
Get started with MuleSoft and API-led connectivity
Salesforce CDC integration using MuleSoft