Thursday 20 June 2019

Asynchronous Apex Triggers | Change Data Capture | Change event trigger

There are many way of asynchronous processing in Salesforce like Future method, Queueable Apex , Batch job, Scheduler Apex and etc. In Summer 19 release Salesforce provide another feature called "Asynchronous Apex Triggers" that can process data asynchronously with the help of Change Data Capture.

A change event trigger is an “after-insert” trigger. The trigger fires after the change event message is published. You can create an after-insert trigger in the Developer Console the same way you create an Apex object trigger after enabling the object for Change Data Capture. To enable the objects for receiving change notification follow below step :-

Setup-> Integrations -> Change Data Capture.



Lets see how we can create the Asynchronous Apex Triggers.


You can create an after-insert trigger in the Developer Console the same way you create an Apex object trigger. When you create a trigger, pick the change event object from the sObject dropdown, which is populated with the change events available in your org.



Asynchronous Apex Trigger


trigger AsyncAccountTriggers on AccountChangeEvent (after insert) {

}


Some Important point to consider :-
  1. Here is list of supported object
  2. For a standard object, the change event name is StandardObjectNameChangeEvent for example AccountChangeEvent
  3. For a custom object, the change event name is CustomObjectName__ChangeEvent for example Employe__ChangeEvent (suffixed as __ChangeEvent) 
  4. Asynchronous Apex triggers are change event triggers that run asynchronously after a database transaction is completed
  5. Available for After Insert Event only
  6. With Asynchronous Apex Trigger we can move complex computations and logic out of the transaction 
Last week we did one session in Asynchronous processes. Here is recording of session




Some Important Link :-


1) Salesforce blog post : https://developer.salesforce.com/blogs/2019/06/get-buildspiration-with-asynchronous-apex-triggers-in-summer-19.html
2) Release Note : https://releasenotes.docs.salesforce.com/en-us/summer19/release-notes/rn_change_event_triggers.htm
3) Trailhead module : https://trailhead.salesforce.com/en/content/learn/modules/change-data-capture/understand-change-data-capture



Thanks
Amit Chaudhary