+ Start a Discussion
NARESH NALLURI 6NARESH NALLURI 6 

What is the difference between synchronous and asynchronous trigger?

Kevin CrossKevin Cross
The problem with triggers in most database environments is the save of the record cannot happen until the trigger completes.  Synchronous triggers must wait until all the events process whereas asynchronous just initiates the request.  Like other valid uses for async, it is when you can do fire-and-forget processing is appropriate.  This is when you need some action to happen but it does not need to happen immediately and is not a requirement for the record action to complete.  In otherw words, I am creating a new Task when an Opportunity is closed.  I want the Opportunity to close but at some point later in the day, I want to end up with a follow-up Task to do something later.  Therefore, in my trigger I could make a call to a future Apex to do the creation of the Tasks.
NARESH NALLURI 6NARESH NALLURI 6
So how to differentiate the synchronous and asynchronous while writing the trigger??
 
Kevin CrossKevin Cross
Triggers are not asynchronous.  The code you call can be.  Therefore, you would create another class that implements @future method (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_invoking_future_methods.htm) then call that from within your trigger, so that the trigger finishes and your @future method handles the processing after the fact.
NagendraNagendra (Salesforce Developers) 
Hi Naresh,

Please find the difference between synchronous and asynchronous trigger below.

Synchronous triggers must complete before further operations can continue. They are typically run when the event is initiated but before it finishes. The event completion is dependent on their success. Triggers are run synchronously by default.

Asynchronous triggers run in the background, independent of other operations that follow. They are typically run after an event completes. To run an asynchronous trigger, the async: prefix must be used.

Here is an example where a Perl email assignment trigger is declared:
async:perl crAssignEmail.pl

please mark my solution as best answer if it helps you.

Best Regards,
Nagendra.P