About Me

My photo
PLANO, Texas, United States

Thursday, September 17, 2020

Platform Event

 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
Characteristics of Platform Event
  •  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
Publishing / Subscribing Platform Events-













Publish Platform Events

We can publish platform events in 3 ways:
  1. Publish Events Messaging using APEX- User EventBus.publish() method to publish
  2. Publish Events Messaging using Declarative tools 
  3. Publish Events Messaging using Salesforce API from external app

Subscribing Platform Events :

We can subscribe to the platform events with the following ways :
  1. Apex Trigger-Write an “after insert” Apex trigger on the event object to subscribe to incoming events.
  2. Subscribe to platform event notification in Lightning components
    1. Lightning web components :  Use the empApi methods in your Lightning web component, import the methods from the lightning/empApi module as follows

      import { subscribe, unsubscribe, onError, setDebugFlag, isEmpEnabled }
          from 'lightning/empApi';
    2. 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"/>
  3. In an external app, you subscribe to events using CometD as well.
  4. Flow and process builder. Check this post.
To know about other integration API at a glance, pls Click here

No comments:

Post a Comment