Subscribe To Salesforce Platform Events Using MuleSoft

Author: Arif Ali Mansuri

This blog introduces subscriptions to Salesforce Platform Events using the MuleSoft Salesforce connector.

Let’s have a look.

Prerequisites for the Integration:
  1. MuleSofts’s Anypoint Studio 7. X
  1. Salesforce Orgs Credentials  
  • Salesforce Access Token 
  • Username 
  • Password 
What is a Salesforce Platform Event?

Salesforce platform event is a message-driven (or event-driven) software architecture consisting of event producers, event consumers, and channels. This architecture decouples event producers from event consumers and simplifies the communication model for connected systems, making it suitable for large distributed systems.


A significant state change in a business process. For example, an order is a significant event because fulfillment centers expect notification before processing an order.

Event message

A message containing information about an event is also known as an event notification. An example of an event message is an order notification containing information about an order.

Event producer

The entity that issued the event message.

Event channel

A stream of instances. Instance producers send event messages, and event consumers read those messages. A platform event channel can be dedicated to a single platform event, or customized to group event messages from many platform events.

Event consumer

A consumer subscribes to a channel and receives communications from the channel. Consider an order processing app that receives notifications of new orders.

The Event Bus

Platform event messages are posted to the event bus where they are stored temporarily. You can retrieve stored event messages from the event bus using the Streaming API (CometD) or Pub/Sub API clients. Each event message contains a ReplayId field that identifies the event in the stream and allows the stream to be replayed after a specific event. For more information, see the “Message Reliability” section of the Streaming API Developer Guide.

Let’s create a Platform Event in the Salesforce org.

Steps to create a platform event in Salesforce org:

  • Step 1: Go to Setup and search Platform Event Settings
  • Step 2: New Platform Event
  • Step 3: Provide the correct label and deployment type
  • Step 4: Create custom fields and relationships (optional)
  • Step 5: Save

Publish a Platform Event: 

We can publish our platform events using flows/Apex/triggers and here we are publishing our platform events through Salesforce flows

Publishing Platform Events using Flows from Flow Builder:

Steps for creating flows:

  • Step 1: Go to Setup
  • Step 2: Search for Flow
  • Step 3: Create a New Flow
  • Step 4: Select a Flow Type
  • Step 5: Add (Screen/Add Record)
  • Step 6: Save and Activate
  • Screen Flow: Provide a user interface to collect records from end users (client side).
  • Record-Triggered Flow: Fired when a record is created, updated, or deleted. This automatically starts thread runs in the background.
  • Schedule-Triggered Flow: It runs frequently and at specific times for each item in the batch.
  • Platform Event-Triggered Flow: Fired when a platform event message is received. This automatically starts thread runs in the background.
  • Autolaunched Flow (No trigger): Executed when an Apex process, REST API, etc. is called, this automatically starts thread runs in the background.
Now, subscribe to Platform Events using the MuleSoft Salesforce connector.
  • Create a new Mule project in Anypoint studio.
  • Add the Salesforce connector form and add modules in the Mule palette.
  • Do the configuration for the Salesforce component with username, password, & security token.
  • Replay Channel Listener

Subscribe to streaming channels. This source provides channel-related notification settings for new events and events stored by Salesforce within a 24-hour retention period. A flow is triggered when an event occurs on the specified channel source.

  • Add logger with #[payload] in the flow.
  • Save & deploy your Mule application.
Publish event messages in the platform event channel by flow.
Here the event message is subscribed in the Mule application. See the logs below.
INFO  2023-01-03 14:07:05,941 [[MuleRuntime].uber.01: [test1-project].test1-projectFlow.CPU_LITE @42aba0f7] [processor: test1-projectFlow/processors/0; event: cd967c40-8b41-11ed-a951-c025a540da68] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 
{ "data": {"Company_ID__c": "teste",  "CreatedById": "0055j0000022lPnAAI", "Billing_Account_Id__c": "teste", "CreatedDate": "2023-01-03T08:36:58.492Z", "User_Id__c": "teste","Org_Id__c": "teste"}, "replayId": 15451878, "createdId": null}

We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.