Posts

Showing posts with the label Platform Events

LinkedIn

Batch Apex - Better Exception Logging using Standard Platform Event - BatchApexErrorEvent

Image
BatchApexErrorEvent is a standard platform event introduced by Salesforce as part of API version 44.0. This mainly helps us to get the details of unhandled exceptions that happened from Batch Apex. To fire exception details to BatchApexErrorEvent, Batch Apex should implement  Database.RaisePlatformEvents interface. Let us cover below in detail: 1. BatchApexErrorEvent Details BatchApexErrorEvent holds below details: Let us implement a batch apex and see how BatchApexErrorEvent is helpful for tracking unhandled exceptions. 2. Sample Batch Apex Scenario Both Account and Contact has a field called Active__c which contains 2 values - Yes, No. When a parent Account is getting deactivated,ie Active=No, we need to mark all child contact's Active also as No. Batch Apex Logic Below Class is implemented to solve this. You can see that this class has implemented  Database.RaisePlatformEvents interface. public with sharing class Batch_ContactDeactivation implements Database.Batchable<...

OrderStatusChangedEvent - Salesforce Standard Platform Event fired during Order Status Changes

Image
 A sales process is normally completed by placing an order and contracting the products. In most cases, the actual ordering will be happening in an external system and not in salesforce. So in this case it is important to send order-related changes to the external system as soon as its status is updated in salesforce. Salesforce has introduced a new standard platform event to support this-  called  OrderStatusChangedEvent. This is available as part of API version 51.0 and above. Let us see this in detail: How to enable OrderStatusChangedEvent  Under Order Setting, we can enable this standard platform event: Setup->Feature Settings->Sales->Order Setting->Enable Order Events When this will be fired? This standard platform event will be fired when: 1. Status is updated for an existing order Supported Subscribers OrderStatusChangedEvent can be subscribed internally and externally. Subscribing through Flows Let us see an example of how to subscribe t...

Subscribing to Salesforce Platform Events using External Java Client - CometD

Image
Platform Events follow event based Architecture, where multiple subscribers can subscribe to a published event in real time manner.  Below diagram shows the basic Architecture of the event-based communication Model: Event - This is a change in state for a business process Event Message - Data about the event Producer - Publisher of the event Event Bus - A communication and storage service for published events Event Consumer - A subscriber to the channel Platform events can be subscribed internally and also externally Platfrom events  - Internal Subscription Below are some scenarios in which you can consume platform events internally: 1. When we need to execute functionalities asynchronously to save govornor limits 2. To build a proper exception logging framework - You can find more details here  How to subscribe Internally? we can see more details about this in a different blogpost. Platfrom events  - External Consumption Many Organizations are moving to event-bas...