Mytutorialrack

Salesforce platform events are used to deliver secure and scalable custom notifications from Salesforce to external systems. Platform events are also used to communicate within Salesforce and also between lightning applications.
Events are sent independent of the receivers listening to those events. I have explained the events using the diagram below:

Salesforce Platform Events

As you can see above, Event producer sends events to the event bus and the event consumer listens for the event. There can be a single producer or also multiple producers.

Platform Events allow for the real-time transmission of event data both within and between the Salesforce platform and other platforms. In other words, this is how Salesforce may notify other modules and external platforms when changes have been made that they need to take into consideration.

Platform Events are an integration pattern (or integration capability) for Salesforce that leverages the Streaming API. They use a Publish/Subscribe paradigm, also known as pub/sub, which minimises the amount of point-to-point connections needed inside your tech stack and eliminates the need for an integration layer to link Salesforce with external systems. This approach is in line with “event-driven architectures.”

Platform Events Terminology

Event: A significant shift in a business process’s condition. An order placing, for example, is a significant event since the order fulfilment centre needs to be notified in order to process the order.

Alert for Events: A message that contains info about the occurrence. Also referred to as an event alert.

Event Coordinator: The person who broadcasts an event message via a channel.

Route: A channel via which an organiser of an event sends out a message. Customers of the event subscribe to the channel in order to get messages.

Event Participant: A channel subscriber who gets messages from the channel.

What Do Salesforce Platform Events Mean?

As previously stated, Platform Events allow for the real-time interchange of event data both within and across the Salesforce platform and other platforms. Platform Events are a native Salesforce feature that functions as follows:

Producer of events: A producer of events organises an event.

Event bus: The event is added to the event bus (also known as the channel), which functions as a queue and executes each event sequentially in a precise chronological order.

Event consumers: People who sign up for an event. The event consumer will be informed as soon as the event is added to the event bus.

Because the event consumer only has to know about the event record via the event bus, rather than the event producer, this method lessens the interconnections between complicated systems.

Re explained: Salesforce Platform Events

In the future, you will be able to identify Platform Events if you hear the buzzword “event-driven architecture” in relation to Salesforce. Fortunately, my partner enjoys cooking, unlike some of us who detest it!

Let’s say we take a vacation with two other couples. While he is cooking in the kitchen, the rest of us are starving. We are unable to communicate since we are in various areas of the house—possibly upstairs and at the pool.

When I knock on the kitchen door first, he says, “No,” to my question, “Hey, is food ready?” When our friend knocks the following minute and says, “Hey, is food ready?” he responds with the same question. He will eventually run out of patience and reach his breaking point, especially if another friend knocks on his door.

Assume that Salesforce is experiencing this. We could keep knocking on Salesforce’s “door” for updates if the person in the kitchen is Salesforce and the pals are all on separate platforms. When external platforms, for instance, knock on Salesforce’s door and ask, “Have there been any Account changes?” Salesforce will likely reply, “No, no… no.” This is because external platforms need to know if there have been any changes to Salesforce account records.

Instead, my partner decided to start a WhatsApp group so that they could talk to one another. He emailed us the link and said we could join the group conversation to find out when the food was ready. He would notify us by broadcast when the dinner was ready. It’s excellent for us because we know right away that dinner is cooked without having to check several times, and it’s fantastic for him since he’s not pushing his patience limit.

The allure of platform events lies in this. When it comes to API calls, Salesforce is not at capacity, and external platforms will be immediately notified of any pertinent modifications made to Salesforce data.

Platform Events, to put it briefly, are Salesforce broadcasts of changes.

When to use platform events?

  1. Platform events are very useful when you want to communicate Salesforce with any external system.
  2. Platform events are also used to communicate between two lightning applications.
  3. Platform events are very useful when you want to communicate between two Visualforce pages.

An Event’s Anatomy on the Salesforce Platform

The following elements comprise Salesforce Platform Events:

  • Event bus: This is where events are added and broadcast in chronological order (each event is executed one after the other), acting as a queue.
  • Events: Any modification that must be announced; relationships and fields are part of the event configuration.
  • Event message: The alert containing details about that particular event, such as modified data.
  • Publishers: Applications, both internal and external, that post events to the event bus.
  • Customers: Are able to sign up for events. The event consumer is notified as soon as the event is added to the event bus.
  • Window: A specific time frame.

Due to its growing platform portfolio, Salesforce redesigned a new event bus in 2020; Tableau and MuleSoft were mentioned as important factors in the choice. View this incredibly educational guide about the development of the Salesforce event bus.

Specifying Fields And Objects For Platform Events:

Custom objects can be produced in the same way as Platform Events. The suffix name for the API name is the primary distinction between platform events and bespoke objects. The custom object appends the __c suffix to the API name in platform events, where the API name is suffixed with __e. We are unable to view, edit, or remove event records via the Salesforce User Interface, in contrast to custom objects.

Platform Events only support the types of custom fields listed below:

  • Checkbox
  • Date
  • Date/Time
  • Number
  • Text
  • Text Area (Long)

How to set up a platform event?

Creating of platform event is very similar to the creation of a custom object in Salesforce. Platform event is a first-class object with the same strongly typed, versioned and customizable schema similar to the Salesforce metadata platform.
Go to setup in Salesforce look for platform events click the link “Platform Events” and start creating your platform events.

How to create Platform Events using Apex?

Steps To Create Platform Events:

Navigate to setup and use fast locate to look for platform events.

You must click the New Platform Event Button in order to create a new platform event.

Fill out the Platform Event Details as you go. Points like Label, Description, and Publish Behaviour would be among the details. Platform Event’s API name would contain a __e postfix to indicate that it is an event object. Two forms of publishing behaviour exist.

a) Release Right Away

  • It is irreversible and disregards transaction boundaries.
  • Even if the transaction fails, the event will still be published.
  • It can be utilised for transaction-related logging purposes.

b) Post Following Commitment

  • Publication is contingent upon transaction commitment.
  • Only an event is published if a transaction is committed. Additionally, a problem prevents the event from being published.
  • Transient and subject to rollback.
  • Use this option to define an event only when you are certain that the transaction will commit.

For the specified platform event, create custom fields.

Things to Note regarding Platform Events:

  1. Whenever you are publishing platform events, Governor limits and DML limits are also applied.
  2. You can only use it after insert a trigger for platform events because you can not update event notifications.
  3. You can not query event notifications using SOQL.

To learn more about these platform events. Click the link here

Conclusion

Because Salesforce has invested in this technology, it is dependable, strong, and can significantly improve your architecture. With platform events, you can instantly share event data both inside the Salesforce platform and across Salesforce and other platforms.

Salesforce can notify users of changes in this manner. It’s similar to telling all of your friends in a group chat when the dinner is ready instead of becoming irritated by everyone asking at the same time. It unifies the information.

Share:

Recent Posts