Think. Build. Salesforce Solutions.

Salesforce Consulting Services across Salesforce Clouds & Across App Lifecycles

Blog

Salesforce Platform Events – An Event-Driven Architecture

By |2022-05-25T05:03:19+00:00May 23rd, 2022|

 

Salesforce Platform Events

Platform events make it easier to communicate changes and respond to events. Publishers and subscribers communicate through platform events. One or more participants can listen to the same event and act. In an event-driven architecture, each service publishes an event when it updates or creates data. This helps applications to maintain data consistency and integrity across multiple services without using distributed transactions.

Here are some key terms to remember:

  1. Event: An event is a significant state change in a business process.
  2. Event Message: An event message or notice contains information about the event.
  3. Event Producer: The publisher of event messages across the channel is known as the event producer. Channel:
  4. The channel through which the message is sent by the event producer.
  5. Event Bus: To get the message, the event attendee subscribes to the channel. In Salesforce, this is referred to as the event bus.
  6. Event Consumer: The subscribers to the channel who receive messages from the channel.

Learn more about platform events.

  • SObject like Salesforce Entity
  • suffix: __e
  • ReplayId to play a specific event
  • Only the Check Box, Date, Date / Time, Number, Text, and Text Area fields are available.
  • Publisher / subscriber – based communication
  • No query is needed.
  • Non-uniform play load
  • Define events with different playloads

Considerations for publishing platform events

  1. Publish an event in read-only mode
    In read-only mode, publishing a standard volume platform event raises an exception and does not publish the event.
  2. Persistence of HighVolume platform events
    Events are queued and buffered, and Salesforce tries to publish the event asynchronously. In rare cases, event messages may not be saved on the distributed system during the first or subsequent attempt. This means that the event is not delivered to the subscriber and cannot be recovered.

Platform Events and APEX:

Mixed DML operations, too many SOQL queries, too many DML statements, CPU timeouts: There are reasons for Salesforce governor limits, but even if you follow best practices, you can exceed them. A good developer will explore all the tools available on the platform to find the best approach to solving the problem they are facing

Salesforce Platform Events

Publish Platform Events using Apex:

You can publish event messages from a Force.com app or an external app using Apex or Salesforce APIs and you can subscribe from the Salesforce or external apps or use long polling with cometD as well.

Salesforce Platform Events

Subscribe to platform events using APEX

Apex Trigger: Writes an “after insert” Apex trigger to the event object to subscribe to incoming events. Triggers receive event notifications from various sources, whether exposed via Apex or the API.

Salesforce Platform Events

Apex Batch:

Salesforce Platform Events

Considerations for publishing and subscribing to platform events using Apex

  1. Only support for triggers after insertion
  2. Infinite trigger loops and limits
  3. Publish the event to Apex by setting the text field to an empty string
  4. Platform Event Trigger: OwnerId Field for New Record
  5. No email support from platform event triggers
  6. Repetition of past events

Platform events make it easier to communicate changes and respond to events. You can use platform events to break the Salesforce governor’s limits.

Leave A Comment