With Summer'19 release (API version 44 or later), now it is possible to fire platform events from batch apex. So whenever any error or exception occurs, you can fire platform events which can be handled by different subscriber.
Batch class needs to implement "Database.RaisesPlatformEvents" interface in order to fire platform event.
global class SK_AccountProcessBatch implements Database.Batchable<sObject>,Database.RaisesPlatformEvents{
//batch logic
}
To understand more about platform events please refer below links
Platform Events : Way to Deliver Custom Notifications within Salesforce or to external Application
Here I will be writing simple batch class which process account records and if any errors occurs during update, then all account record Ids will be published using platform event.
I have created platform event with below mentioned fields:
Below is batch apex code which will fire platform event and I wrote a trigger which will subscribe to platform event.
I have used Database.Stateful interface to store the record ids which are getting failed in each batch execution. In finish method, I am firing platform event with all failed records Ids.
Below is logs generated by trigger which will get executed whenever platform event is fired.
In order to see debug logs for platform events subscription, add a trace flag entry for the Automated Process entity in Setup. The debug logs aren’t available in the Developer Console’s Log tab.
Navigate to SetUp --> Debug Logs --> New
Please refer below link to understand how to use platform events in lightning components:
Handling Platform Events in Lightning Components
Batch class needs to implement "Database.RaisesPlatformEvents" interface in order to fire platform event.
global class SK_AccountProcessBatch implements Database.Batchable<sObject>,Database.RaisesPlatformEvents{
//batch logic
}
To understand more about platform events please refer below links
Platform Events : Way to Deliver Custom Notifications within Salesforce or to external Application
Here I will be writing simple batch class which process account records and if any errors occurs during update, then all account record Ids will be published using platform event.
I have created platform event with below mentioned fields:
Below is batch apex code which will fire platform event and I wrote a trigger which will subscribe to platform event.
I have used Database.Stateful interface to store the record ids which are getting failed in each batch execution. In finish method, I am firing platform event with all failed records Ids.
Below is logs generated by trigger which will get executed whenever platform event is fired.
In order to see debug logs for platform events subscription, add a trace flag entry for the Automated Process entity in Setup. The debug logs aren’t available in the Developer Console’s Log tab.
Navigate to SetUp --> Debug Logs --> New
- For Traced Entity Type, select Automated Process.
- Select the time period to collect logs and the debug level.
- Click Save.
Please refer below link to understand how to use platform events in lightning components:
Handling Platform Events in Lightning Components
Hope this will help!!!
This comment has been removed by the author.
ReplyDeleteNice Blog ! If you are facing issues with QuickBooks and need help,dial our toll-free number Accounting Services 1-800-986-4607 without any delay. Get 100% reliable solutions and perform accounting tasks smoothly. We have a toll-free number 1-800-986-4607 on which you can reach anytime you wish.
ReplyDeleteThis is Good information about this topic..I like it.. wordpress database fix ..Keep it Up!
ReplyDeleteI love the way you write and share your niche! Very interesting and different! Keep it coming! Fire alarm systems
ReplyDeleteI think about it is most required for making more on this get engaged יועץ בטיחות כיבוי אש
ReplyDeleteWeb and Pro Infomedia is Best SEO Company in Lucknow
ReplyDeleteThanks for this Useful Information
ReplyDeleteRegards
Best Varicose Vein Treatment in Lucknow
Well, this got me thinking what other workouts are good for those of us who find ourselves on the road or have limited equipment options. industri judi
ReplyDeleteThat is really nice to hear. thank you for the update and good luck. מערכת גילוי אש מחיר
ReplyDeleteI think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. Vacuum casting ABS PC Pom parts
ReplyDeleteThis information about fire is very helpful for us and through this, we can get many benefits. Many people liked this content because it is beneficial for us. Coursework writing services.
ReplyDeleteThis is the most stable release till now. We integrated it in our systems which are used for the best live video monitoring service and it worked just fine, the way we wanted.
ReplyDeleteThanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for.wireless fire alarm system
ReplyDelete