Publish and Subscribe Platform events using Flows

Platform Event

Platform Event is an Event-Driven architecture and used to connect and exchange real-time event data in Salesforce and external apps. Transferring data between the publisher and subscriber is secure and scalable. One or more Subscribers can listen to the published event messages.

Use Case

                Collect and store the employee information in Salesforce and send an email to the respective employee in Salesforce Community (as a Site guest user profile without logging to the Community) using Flows and Platform Events.

How to create Platform Events?

  1. Go to Setup à Enter and choose Platform Events.
  2. Click New Platform Event and set a name for your Platform event and click Save.
  3. Create Custom fields as per your requirement under the Custom Fields & Relationships section. Custom fields support only the following data types,
  4. Checkbox
  5. Date
  6. Date/Time
  7. Number
  8. Text
  9. Text Area (Long)

Publishing the Platform Event

There are many ways to publish platform events such as Apex, Process builder, Flows and by using Salesforce API’s. Here, we are using Flow builder to publish the platform events. By using Flows, we can interact and collect the information from the end-user and this option is available only in the flows. Below find the steps to publish the platform events using the Flows:

  1. Go to Setup à Enter and choose Flows.
  2. Click New Flow and choose Screen flow.
  3. As shown in the below screenshot, create a Screen with the necessary input fields to get the information from the end user.
  4. Add a Create record element then choose the created Platform event object and map the custom fields with the end user input. Once the Platform Event record gets created, the event messages are transferred through the Event Channel.
  5. Finally, Save and Activate the flow.

Subscribe to Platform Events

Published event messages can be received by using Apex trigger, Process builder, Flows or CometD (external clients) subscription method. To subscribe to the platform events through the Flow builder,

  1. Go to Setup à Enter and choose Flows.
  2. Click on New Flow and choose Platform Event-Triggered Flow.
  3. Choose respective Platform event object to subscribe in the Start element.
  4. Drag and drop Create record element and capture the published Platform event field values with the respective Salesforce object.
  5. Drag and drop Action element and choose Email from the Category to send an Email notification to the respective end user.
  6. Finally, Save and Activate the flow.

Collect the input from the user using Screen Flow

                As mentioned in the publisher flow, create a Screen to get the inputs from the user. After creating a Platform event object with the respective fields, map the end user screen input values with the platform event fields in the Create record element to publish an event. While running the flow, it shows the screen to get the real-time data from the user and based on the input, the platform event gets published.

Store the input and send an email using Platform Event-Triggered Flow

Once the platform event is published, then the respective subscriber as mentioned in the subscriber flow gets the published event messages. By using the Platform Event-Triggered Flow, we can get and store the information in Salesforce. Action element in Flows has an option to send an email to the user based on the published input. Optionally, we can use the event messages in the email template subject and body as merge fields.


About MST

At MST Solutions our cornerstone is to adapt, engage and create solutions which guarantee the success of our clients. The talent of our team and experiences in varied business verticals gives us an advantage over other competitors.

Recent Articles

Work with us.

Our people aren’t just employees, they are key to the success of our business. We recognize the strengths of each individual and allow them time and resources to further develop those skills, crafting a culture of leaders who are passionate about where they are going within our organization.