+
+

Lab 1: Change Data Capture - gRPC

Overview

In this module we will set up Change Data Capture in Salesforce so we can start capturing events that occur within the Account object.

Change Data Capture (CDC) allows you to receive near real time changes of Salesforce records, and synchronize corresponding records in an external data store. CDC publishes change events, which represent changes to Salesforce records. These changes include creation of a new record, updates to an existing record, deletion of a record, and undeletion of a record.

Step 1: Setup CDC in Salesforce

In your Salesforce Org please navigate to the Setup. Once logged in you will find the Setup Icon on the right top.

Lab1 Pic1

Within the Setup, use the Quick Find and search for Change Data Capture.

Lab1 Pic2

Within the Change Data Capture Setup you will find the respective Objects/Entities in the left box.

Search for the Contact object and use the arrow button to move these to the Selected Entities in the right box and click Save.

M3L1 001

Great! Lets move to the next step.

Step 2: Creating the Project

Anypoint Studio

Anypoint Studio is MuleSoft’s Eclipse-based integration development environment for designing and testing Mule applications.

Now let’s go build out our Mule Project! First we need to create a new Mule Project via File → New → Mule Project

M3L2 001

Please enter your Projects name with your personal name such as <username>-salesforce-eapi and click Finish.

M3L2 002

Next what we want to do is add our Salesforce Pub/Sub Connector into our Mule Palette. Click Search in Exchange and type in Salesforce Pub/Sub.

Lab2 Pic3

Next we want to add the module and also double check it is the latest version. Do this by clicking the add button in the middle of the screen followed by clicking on the drop down under version. Click Finish to move on to the next step.

Lab2 Pic4

Next click on our newly installed module, Salesforce Pub/Sub and drag and drop the Subscribe channel listener on to the canvas.

Lab2 Pic5

In the next step we will need to add our Salesforce Connector Configuration. Click once on the Subscribe channel listener element and you will see the configuration bar at the bottom of Anypoint Studio. Hit the green + button in order to create a new Configuration and enter your Salesforce Username and Password.

Lab2 Pic6

If you need a security token please refer to Step 2 in Mod 0

Lab2 Pic7

Test your connection by clicking Test Connection button and then click OK once successful and OK once more.

Now that the Connector Configuration is added, Anypoint Studio will crawl Salesforce for available Channels names. Please use the drop down box in order to select the Contact Change Event or type in /data/ContactChangeEvent. For replay options please select the Earliest from the drop down and leave the default batch event size for 100. This means that the Subscriber receives all events, including past events that are within the retention window of the server and new events sent after subscription.

newLab2Pic8

Next let’s add a logger from the Mule Palette to our flow. Click Favourites in the Mule Palette and then drag and drop the Logger into the Process section of our flow.

Click the Logger once, followed by the little fx and then the 6 dots on the right hand side. We will be configuring what payload is being logged.

Lab2 Pic9

In the editor on the right hand side type in the following :

%dw 2.0
output application/json
---
payload.event

Changing the output to json will help the logged messages be more readable. We are also able to view the payload structure on the left hand side to correctly navigate to the changed data.

M3L2 014

To complete the second lab we will now save our project. Click the floppy disk icon on the top left to save your project.

M3L2 013

Well Done! Now on to the last step where we learn how to deploy and test.

Step 3: Deploy and Test

Running and Testing the Application Locally

Let’s locally kick start our application! To do this simply right click somewhere in the white space of your working canvas and select the first option Run Project.

M3L2 016 old

The Anypoint Studio Console will now show up, once the Application is started successfully you should see the following in the console with status DEPLOYED.

Lab3 Pic2

Now that our app has successfully deployed let’s test out our flow. In order to see events in our Console, let’s move to Salesforce and make a change on an existing Contact.

In Salesforce navigate to the Contact object.

M3L3 002

Within the Contacts, switch the view to All Contacts in order to see example Contacts that come with your Developer Org.

M3L3 003

Open one random Contact and apply a Change to any field. For instance adjust the phone number and hit Save.

We recommend to have your Salesforce Org and Anypoint studio Side by side, so you can see the logging in real time with Anypoint Studio

M3L3 Pic5

Congratulations!!! You have successfully connected to Change Data Capture and are now able to view all the events that occur to Salesforce Objects.

Summary

In this lab, you have completed the following steps:

In the next module, we will learn how to use Bulk API using the Salesforce Connector.

Submit your feedback!
Share your thoughts to help us build the best workshop experience for you!
Take our latest survey!