Salesforce Platform Events: Streamlining Connectivity

Salesforce Platform Events: Streamlining Connectivity

Introduction

Salesforce Platform Events enable businesses to achieve real-time communication and integration across their systems. By leveraging event-driven architecture, these events allow asynchronous communication between Salesforce and external systems, driving efficiency and automation.

What Are Salesforce Platform Events?

Salesforce Platform Events are a form of message exchange that facilitates communication between different applications inside and outside of Salesforce. Unlike traditional point-to-point integrations, Platform Events allow for the broadcasting of event data to multiple subscribers at once.

This approach follows the principles of event-driven architecture, where events trigger actions or updates without needing constant polling. Platform Events are designed to work asynchronously, meaning that the sender and the receiver don’t need to interact in real-time. This makes it easier to manage complex workflows and reduces the need for tight coupling between systems.

Whether you’re triggering a process within Salesforce or integrating with external applications, Platform Events serve as a powerful tool to distribute real-time data and automate business processes.

Key Components of Salesforce Platform Events

Event Producers and Consumers

Salesforce Platform Events rely on the concepts of event producers and consumers. Producers are systems or processes that create and publish events to the Salesforce event bus. Consumers, on the other hand, are systems that subscribe to and act on these events.

Producers and consumers are decoupled, meaning the producer doesn’t need to know which consumers are subscribed. This separation makes the system more flexible and scalable, allowing multiple consumers to handle events in their own way.

Event Channels

Event channels are the pathways through which Platform Events are communicated. Each event is published to a channel, and consumers subscribe to that channel to receive notifications of the event.

Event channels in Salesforce are highly customizable. You can define specific channels based on business requirements, ensuring that only relevant systems receive the necessary data. This control improves the efficiency of event processing and ensures that communication remains organized and efficient.

Use Cases 

Salesforce and external systems communicate through platform event messages.

News agency sends events to subscribed clients with the latest breaking news about traffic and road conditions in a mountain retreat destination

Use platform events in the following cases:

  • To send and receive custom event data with a predefined schema
  • To publish or subscribe to events in Apex
  • For the flexibility of publishing and processing events on and off the  Salesforce platform

Create Platform Events 

From Setup, enter Platform Events in the Quick Find box, then select Platform Events.

On the Platform Events page, click New Platform Event.

You define the custom data that platform events contain. Just like custom objects, you define platform events in Salesforce. You create a platform event definition by giving it a name and adding custom fields.

Let’s say CloudNews wants to notify its subscribers of its product launches. We’ll create a Platform event object called CloudNews and a few fields to store the message.

Publish Platform Events

If your app is on the Salesforce platform, you can publish events using an Apex method or with declarative tools, such as Process Builder or the Cloud Flow Designer. If your app is an external app, you can publish events using Salesforce APIs.

To publish more than one event in the same call, add your events to a list of events, and pass the list to the EventBus.publish() method. The output of this method is an array of Database.SaveResult objects

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 to listen to the news event and create a follow-up Case if the news event is an Urgent one.

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.

Summary

Salesforce Platform Events play a crucial role in enabling real-time, scalable integrations for businesses. By understanding how they work and applying best practices, businesses can significantly enhance their Salesforce operations and drive efficiency across multiple systems.

 

Contact Us

We would love to hear from you Please feel free to send us a message via the form

DMCA.com Protection Status