In our last blog post, we’ve explained what Platform Events are and how to publish them in Salesforce. In this post, we’ll be talking about Subscribing/Listening to the Platform Events to be notified of the latest news.

You can receive event notifications via Apex triggers, process builder, and visual flows.

Subscribe with Apex Triggers

Apex Triggers receive event notifications from various sources—whether they’re published through Apex or APIs. Platform events support only after insert triggers. After an event message is published, the after insert trigger is fired.

Continuing with the same event we created in our last post, Cloud_Fountain__e. Let’s create a trigger to listen to the news event and create a follow-up Case if the news event is an Urgent one.

Subscribe with Process Builder

To subscribe to event messages without code, create a process that starts when a platform event occurs.

Setup → Process Builder → New Process. From the drop-down for the process starting point, choose ‘A Platform Event Occurs’

Create Process Builder on Platform Events (for subscribing).

Then in the Add Trigger → Choose CloudFountain Platform Event. Let’s take it further and say subscribe only if the event is sent from a particular contact only, you can set the matching conditions. This can be varied per your requirements.

Add Platform Event to trigger Process Builder.

As we did in the trigger, we create an immediate action to create a new Case record as shown below.

Create Action on Process Builder for the Platform Event.

Subscribe with Flows

Similarly, you can subscribe to a platform event message with a Flow by using a Wait element. Instead of starting a flow when a platform event occurs, a flow that was started previously waits for a platform event and then resumes.

Here’s an example of a Wait element that waits for a CloudFountain event message to occur. The flow resumes only if the Event’s location matches {!MailingCity_Location.MailingCity}.

Subscribe to Platform Event with Flows Wait Event.

{!MailingCity_Location} is just a variable in the flow.

Considerations while implementing platform events subscription:

  • There might be a delay between when an event is published and when the trigger processes the event since platform event trigger runs in its own process asynchronously.
  • A trigger processes platform event notifications sequentially in the order they’re received. An Apex trigger can receive a batch of events at once. The order of events is preserved within each batch.
  • Platform Events run under the Automated Process system user and not under the one who executed it.
  • System fields of records such as CreatedById and LastModifiedById also reference the Automated Process System user.
  • Platform Event triggers are subject to Apex governor limits and Apex Trigger Limits as usual.

Use Platform Events for any number of applications and integrations, such as processing business transactions or engaging in customer service.

Thank you for visiting the page. Please feel free to post your invaluable feedback, comments, and questions. We @CloudFountain will be glad to assist you with your Salesforce implementation.

Related posts