You need to sign in to do that
Don't have an account?
Asynchronous Apex Triggers vs. @future-Annotation
Hi everybody
I read the article "Get #Buildspiration with Asynchronous Apex Triggers in Summer ‘19" (https://developer.salesforce.com/blogs/2019/06/get-buildspiration-with-asynchronous-apex-triggers-in-summer-19.html) a few days ago a had to think about the question "What is the difference between event-driven asynchronous apex trigger vs. @future-Annotation".
I can't think of an academically 100% correct answer right now, because both do the same: They outsource very limit-intensive (related to execution governors and limit) out of the current apex-transaction.
But, why and when should I use @future-Annotation and when event-driven asynchronous apex trigger?
I hope we can discuss this topic together and find a solution to understand vor everyone.
Best regards,
Christian
The former trigger was always synchronous itself but now you can have this primary trigger also asynchronous.
The difference is subtle when you use few lines of code in the synchronous trigger before calling a future method (inside the synchronous trigger).
"Perform resource-intensive business logic asynchronously in the change event trigger and keep transaction-based logic in the Apex object trigger. By decoupling the processing of changes, change event triggers can help reduce transaction processing time." (Salesforce)
The synchronous Apex object trigger is still needed for the validation of a form for example (transaction-based logic).
The asynchronous Apex event trigger (always after insert) is used to initiate an asynchronous treatment from the trigger itself even if you use @future finally again like below.
React to Changes with Apex Triggers :
Future method: ProductNotifications.notifyOnLowOnStockProductUpdates
https://help.salesforce.com/articleView?id=external_object_change_tracking_example_create_triggers.htm&type=5 (https://help.salesforce.com/articleView?id=external_object_change_tracking_example_create_triggers.htm&type=5)
They are complementary.