Salesforce has a unique way to approach different customers. Salesforce allows the admin of a company to broadcast any particular message to various other terminals. For example, if a manager wants to send a message to every employee in the organization then platform events can be used to perform this task.
Meanwhile, check out our Salesforce Training YouTube video!
A Platform Event is a special type of Salesforce entity that is similar to Salesforce custom objects. You can create a platform event definition and then add custom fields in custom objects.
The events get sent to the user anyway whether the user acknowledges it or not. Platform events are the event messages or notifications that your apps send and receive to take further actions. It simplifies the process of communicating changes and responding to them without writing complex logic.
Publishers and subscribers communicate with each other through these events. One or more subscribers could listen to the same events and carry out the actions required to perform.
Want to learn Salesforce in depth? Go through the Salesforce Training in Bangalore provided by Intellipaat!
Let us take an example of order management. When the Order management app creates an Order in a pending state and publishes an Order Created event. Customer Service receives the event and attempts to process an Order. It then publishes an Order Update event. Then Order Update Service receives the event from the changes in the state of the order to either approved or canceled or fulfilled. The following diagram show the event-driven architect
Event
A change in state that is meaningful in a business process. For example, a placement of an order is a meaningful event because the order fulfillment center requires notification to process the order.=
Event Notifier
A message that contains data about the event. Also known as an event notification.
Event producer
The publisher of an event message over a channel.
Channel
A conduit in which an event producer transmits a message. Event consumers subscribe to the channel to receive messages.
Event consumer
A subscriber to a channel that receives messages from the channel. A change in state that is meaningful in a business process.
But when you overlook Platform events it makes similar to Streaming API and most of the futures including the replayID and durability but below makes the difference between streaming API.
- Platform events are special kinds of entities similar to a custom object
- You can publish and consume platform events by using Apex or a REST API or SOAP API.
- Platform events integrate with the Salesforce platform through Apex triggers. Triggers are the event consumers on the Salesforce platform that listen to event messages.
- Unlike custom objects, you can’t update or delete event records. You also can’t view event records in the Salesforce user interface, and platform events don’t have page layouts. When you delete a platform event definition, it’s permanently deleted.
- Platform events may be published using declarative tools (Process Builder)
- platform events can also be subscribed to using APEX or decoratively process builder and flow
Here is a list of uses of Platform Events in Salesforce-
Delivering Custom Notifications
Platform events are a part of Salesforce’s corporation messaging platform. The platform offers an event-pushed messaging structure to allow apps to talk outside and inside of Salesforce.
Real-time Event Monitoring Object
For most platform events used in Real-Time Event Monitoring, corresponding Salesforce event objects store the event data.
For increased security, you can enable encryption of platform event messages while they’re stored in the event bus in a Shield Encryption org.
External apps use an API to publish platform event messages. Publish events by inserting events in the same way that you insert objects. You can use any Salesforce API to create platform events, such as SOAP API, REST API, or Bulk API.
Receive platform events in processes, flows, Apex triggers, or CometD clients.
Add Apex tests to test platform event subscribers. Before you can package or deploy Apex code, including triggers, to production, it must have tests and sufficient code coverage. Add Apex tests to provide code coverage for your triggers.
To get usage data for event publishing and delivery to CometD and Pub/Sub API clients, query the PlatformEventUsageMetric object. Usage data is available for the last 24 hours, ending at the last hour, and for historical daily usage. PlatformEventUsageMetric is available in API version 50.0 and later.
Learn about special behaviors related to defining, publishing, and subscribing to platform events. Learn how to test platform events. And get an overview of the various events that Salesforce offers.
The messages sent by the Salesforce admin as notifications have a particular limit. The maximum event message size that you can publish is 1 MB. If your event object has hundreds of custom fields or many long text area fields, you could hit this limit. In this case, the publishing call gets an error.
Preparing for a Salesforce Admin Interview! Check out our Salesforce Admin Interview Questions and Answers.
Get 100% Hike!
Master Most in Demand Skills Now!
Salesforce and external systems communicate through platform event messages. Some Use Cases are-
- News organizations send notifications to subscribed customers or paid customers whenever any big news comes up.
- An external product app notifies Salesforce of merchandise returns.
Check out the blog on Future Methods in Salesforce.
After a platform event has been defined in your Salesforce org, Publish Event messages from a Salesforce app using processes, flows, or Apex or an external app using Salesforce APIs.
- Publish Event Messages with Flows – Use flows to publish event messages from a Salesforce app as a part of few-person interactions, an automatic process, Apex, or workflow action.
- Publish Event Messages using Salesforce Declarative Tools like Process Builder – We can use the Salesforce platform events process builder to publish event messages from a Salesforce app as part of an automated process. These Declarative Tools in Salesforce help a lot to publish Event Messages in Salesforce
- Publish Event Messages with Apex – Use Apex to publish event messages from a Salesforce app. To publish event messages, call the EventBus.publish method.
For example, if you defined a custom platform event called Low Ink, reference this event type as Low_Ink__e. Next, create instances of this event, and then pass them to the Apex method.
- Publish Event Messages with Salesforce APIs – Publish events by inserting events in the same way that you insert objects. You can use any Salesforce API to create platform events, such as SOAP API, REST API, or Bulk API. When publishing an event message, the result that the API returns contains information about whether the operation was successful and the errors encountered. If the success field is true, the publish request is queued in Salesforce and the event message is published asynchronously.
- Get the Status of Asynchronous Platform Event Publish Operations (Beta) – High-quantity platform occasions are posted asynchronously. With submit popularity occasions, you could music the popularity of publishing operations and take vital actions. Enable popularity occasions at the high-quantity platform occasion you’re inquisitive about tracking.
- From Setup, enter Platform Events in the Quick Find box, then select Platform Events.
- On the Platform Events page, click New Platform Event.
- Create a Notification platform event with the following settings:
- Label: Notification
- Plural Label: Notifications
- Object Name: Notification
- Description: Real-time notifications
- Click Save.
- On the Notification platform event page, click New in Custom Fields & Relationships.
- Select Text as the field data type.
- Click Next.
- Set the following values:
- Field Label: Message
- Length: 255
- Field Name: Message
- Description: The notification message
- Required: Check the box next to “Always require a value in this field in order to save a record”
- Click Save.
Learn more about salesforce platform licenses from our comparison blog on Salesforce vs Salesforce platform licenses!
Conclusion
In this blog, we have covered all the crucial aspects of Salesforce platform events and their different use cases. If you want to learn salesforce right from the scratch or want to expand your knowledge on the subject enroll yourself in our Salesforce Training now!