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.

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

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}.

{!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.

Author: CloudFountain

We started as a side business in 1999 and have since grown to become a leading provider of IT solutions for businesses. With around 30 employees across several countries, we offer a wide range of services, including IT support, hosting, and custom software development.Over the years, we have served approximately 1000 customers, ranging from small startups to large enterprises. Our mission is to provide cutting-edge technology solutions that help our clients achieve their business goals. We pride ourselves on our exceptional customer service and attention to detail, and we work closely with each client to understand their unique needs and provide tailored solutions that meet their specific requirements.At CloudFountain, we believe that technology can be a powerful tool for growth and success. That’s why we stay on top of the latest trends and advancements in the industry, so we can provide our clients with the best possible solutions. Whether you need IT support, hosting services, or custom software development, our team of experts is here to help. Contact us today to learn more about how we can help your business succeed.