Create and consume a Salesforce Platform Event using Mule 4 with no code

Edgar Moran
Another Integration Blog
4 min readJan 22, 2024
Photo by fabio on Unsplash

The world of data is moving faster than ever; to keep up with it demands agility and real-time responsiveness. Salesforce Platform Events are here to help by enabling real-time data notifications across your Salesforce org and beyond. And guess what? Mule 4 makes integrating and leveraging these events a breeze!

In this article, I will explain in just a few steps how we can start sending data from Salesforce into Mule. Mule may then use that data for consuming other services or may simply process that data in an asynchronous way.

Create the Platform Event object in Salesforce

We start by creating our platform event within Salesforce. Click the gear in the top right of the page to go into Setup. Type “Platform Event” in the search bar to bring up the Platform Events Setup.

Locating the Platform Events Setup

From there, simply click on “Create new Platform Event” and populate the required fields; in this case, just give a meaningful name to the platform event. Click on “Save” to proceed.

Creating a new platform event within Platform Events Setup

In the Custom Fields and Relationships section, let’s create a couple of fields we can use to map Account Name and Account Description:

Specifying custom fields to return values for within the Account Platform Event

We have specified here the two fields from Account which we want to send over in our platform event. The API names for these two custom fields are Account_Description__c and Account_Name__c.

Let’s move on to the next configuration step.

Create the Platform Event using Flow

The platform event has been created, and we have a couple of fields we can use from the event. Now we need a way to push the data into the platform event every time an Account is created or modified; Salesforce Flow is going to help us to do just that.

From the search bar, type “Flow” to bring up the Flows Setup. Click on “New Flow”:

Bringing up the Flows Setup

Select Record-Triggered Flow, and we should then be able to see the canvas to start setting up our process.

Selecting Record-Triggered Flow as the flow type

We start by selecting the Account object. For the Trigger, select “A record is created or updated”, and make no other changes for now.

Configuring the Record-Triggered flow for the Account object

Next, we click the + sign to add a new element to the flow. Type “create” to search for and select the “Create Records” action:

Adding a Create Records action to the flow

Now we need to give a name to our action. For the Object type to Create a Record of, select Account Platform Event:

Selecting Account Platform Event as the type of object to create

On the left-hand side of the Field section, we select the couple of fields we previously created in the Platform event, Account_Name__c and Account_Description__c. On the right-hand side, we map values to the fields using this notation like this: {!$Record.Description}

Mapping values to the Account Platform Event fields

The completed flow should look like the following:

The completed flow

Click on the Save button to commit the changes.

At this point, anytime a new Account gets created or updated, details regarding the change are collected and transmitted as a platform event.

The Mule application

Next, we hop into Anypoint Studio to create our Mule 4 application with a new flow to listen to a Salesforce channel. From the Mule Palette, simply click the Salesforce component and then type “replay” in the search box to narrow down the available operations. Click and drag the Replay channel listener operation to the application canvas.

Dragging a Replay listener operation from the Mule palette to the Mule application canvas

We can then specify the name of our Streaming channel for the Salesforce Platform Event API as /event/Account_Platform_Event__e:

Specifying the name of the Streaming channel for the Account Platform Event

And that’s all there is to it to get started! After we have deployed our Mule application and it is up and running, we may then go browse its log after we have created or updated an account record in Salesforce.

Viewing the log output for an Account Platform Event received by the Mule application

There are many possibilities from which you can take it from here.

I hope this helps to demonstrate how fast and easy it is to create such an integration between Salesforce and Mule, and then set it off and running.

--

--

Edgar Moran
Another Integration Blog

@Mulesoft Ambassador | Software Engineer @Cisco Meraki | Ex-Twitter | Sr. Force.com developer | innovating in technology, love coding, and photography !