Platform events in Salesforce !

    sfdcsharepoint.com

    Salesforce has recently introduced this feature and its much needed one. Let’s understand couple of Terms before going into deep.

    n

    I am using TrailHead reference to write on this topic.

    n

    Event

    n

    A change in state that is meaningful in a business process.

    n

    Event message

    n

    A message that contains data about the event. Also known as an event notification.

    n

    Event producer

    n

    The publisher of an event message over a channel.

    n

    Event channel

    n

    A stream of events on which an event producer sends event messages and event consumers read those messages. Also called an event bus in Salesforce.

    n

    Event consumer

    n

    A subscriber to a channel that receives messages from the channel.

    Platform Events and sObjects

    A platform event is a special kind of Salesforce entity, similar in many ways to an sObject.

    n

    An event message is an instance of a platform event, similar to how a record is an instance of a custom object. Unlike with custom objects, you can’t update or delete event records, or view event records in the Salesforce user interface.

    n

    You can set read and create permissions for platform events. You grant permissions to users in profiles or in permission sets.

    Using Platform Events in Native and External Apps

    Platform events enable the flow of event messages within Salesforce and to or from external apps.

    n

    Apps on the Salesforce platform use an Apex method to publish events and an Apex trigger to consume events. Also, Visualforce and Lightning component apps can subscribe to events using CometD.

    n

    As an alternative to code, you can publish events with declarative tools, such as Process Builder and Cloud Flow Designer.

    n

    Finally, external apps publish events using the sObject API and consume events using CometD clients.

    Differences Between Platform Events and Other Streaming Events

    Other events include PushTopic and generic events.

      n

    1. With PushTopic events, clients receive messages about changes in Salesforce records based on a predefined query.
    2. n

    3. With generic events, you can send and receive arbitrary message content (payloads) not necessarily tied to Salesforce records.
    4. n

    Platform events are similar to generic events but offer more powerful customization. With platform events, you can publish any custom data. You define the schema of event data at a granular level as typed fields. Also, you can use platform events in native Salesforce platform apps and external apps alike.

    n

    Use platform events in the following cases:

      n

    1. To send and receive custom event data with a predefined schema
    2. n

    3. To publish or subscribe to events in Apex
    4. n

    5. For the flexibility of publishing and processing events on and off the Salesforce platform
    6. n

    n

    n

    n

    n

    n

    n

    n

    Source : (Trailhead)

    ReplayId System Field and Event Retention

      n

    1. Salesforce stores platform events for 24 hours. You can retrieve stored events in API clients but not in Apex.
    2. n

    3. Each event record contains a field, called ReplayID, that the system populates after the event is published.
    4. n

    5. Each replay ID is guaranteed to be higher than the ID of the previous event, but not necessarily contiguous for consecutive events.
    6. n

    7. You can retrieve all stored events, or you can specify the replay ID of an event as the baseline for the retrieved portion of events.
    8. n

    Note : You can retrieve past events only when subscribing in CometD and using a ReplayId option.Even though Salesforce retains event records temporarily, you can’t query them through SOQL or SOSL. Similarly, you can’t use event records in the user interface in reports, list views, and search.

    n

    How to Publish Event: (Do Practice from TrailHead.

      n

    1. Publish Events Messaging using APEX.
    2. n

    3. Publish Events Messaging using Declarative tools (Process Builder or Cloud flow Designer Tool / Visual Work flow)
    4. n

    5.  Publish Events Messaging using Salesforce API from external app.
    6. n

    Unlike with custom objects, platform events aren’t processed within database transactions in the Salesforce platform. As a result, published platform events can’t be rolled back.

    n

    Note :

      n

    1. The allOrNoneHeader API header is ignored when you publish platform events through the API.
    2. n

    3. The Apex setSavepoint() and rollback() Database methods aren’t supported with platform events.
    4. n

    When you publish platform events, DML limits and other Apex governor limits apply.

    n

    How to Subscribe to Events :

      n

    1. Apex triggers receive event notifications.n
    2. n

    3. write an after insert Apex trigger on the event object to subscribe to incoming events.
    4. n

    5. Triggers receive event notifications from various sources—whether they’re published through Apex or APIs.
    6. n

    7. Visualforce and Lightning component apps receive events through CometD.n
    8. n

    9. CometD is a scalable HTTP-based event routing bus that uses an AJAX push technology pattern known as Comet.
    10. n

    11. In an external app, you subscribe to events using CometD as well.
    12. n

    Leave a Reply

    Your email address will not be published. Required fields are marked *