What is Platform Event?
- Platform Event is based on Event-Driven Architecture enable apps to communicate inside and outside of Salesforce.
- Platform events are based on the publish/subscribe model and work directly with a message bus that handles the queue of incoming events and processes listening for them. This is built-in real-time integration patterns in the Salesforce Platform which help to reduce point-to-point integration
What is Event-Driven Software Architecture?
An event-driven (or
message-driven) software architecture consists of event producers, event
consumers, and channels.
- Event: A change in state that is meaningful in a business process.
- Event message / Notification: A message that contains data about the event.
- 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. Also referred to as event bus in Salesforce.
- Event consumer: A subscriber to a channel that receives messages from the channel
- SObject like Salesforce Entity
- Suffixed with __e
- Only Checkbox, Date, Date/Time, Number, Text, and Text Area field available.
- Pub / Sub based communication
- No Polling required. Whenever an event occurs, the consumer will get notified
Difference between SObject and Platform Events-
- Platform event only support insert whereas sObject support all DML
- You can not query Platform events through SOQL or SOSL
- You can not use Platform in reports, list views, and search. Platform events don’t have an associated tab
- Published platform events can’t be rolled back.
- Only after insert Triggers Are Supported
Publish Platform Events
We can publish platform events in 3 ways:
- Publish Events Messaging using APEX- User EventBus.publish() method to publish
- Publish Events Messaging using Declarative tools
- Publish Events Messaging using Salesforce API from external app
Subscribing Platform Events :
We can subscribe to the platform events with the following ways :
- Apex Trigger-Write an “after insert” Apex trigger on the event object to subscribe to incoming events.
- Subscribe to platform event notification in Lightning components
- Lightning web components : Use the empApi methods in your Lightning web component, import the methods from the lightning/empApi module as followsimport { subscribe, unsubscribe, onError, setDebugFlag, isEmpEnabled }
from 'lightning/empApi'; - Subscibe in an Aura Component : Use the empApi methods in your Aura component, add the lightning:empApi component inside your custom component and assign an aura:id attribute to it<lightning:empApi aura:id="empApi"/>
- In an external app, you subscribe to events using CometD as well.
- Flow and process builder. Check this post.
To know about other integration API at a glance, pls Click here
No comments:
Post a Comment