function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC ROCKSFDC ROCK 

How can we make apex trigger asynchronous ?

@anilbathula@@anilbathula@
Hi Subodh,

triggers are synchronous process, you can call an asynchronous process from trigger using  future method but there is a limit of 10  future call per invocation.

Trigger:-
trigger syncAccount on Account(after insert)
  { 
   for(Account a : Trigger.new)
   {
	SendAccountasync.callcreateAcc(a.Name, a.Id);
    }
  }
Class:-
public class SendAccountasync {
@future(callout=true)
    public static void callcreateAcc (String accName, String accId)
    {
           System.debug('Account Name====>'+accName);
           System.debug('Account Id=====>'+accId);
    }
}

Thanks
Anil.B
 
Raj VakatiRaj Vakati
The way to execute a callout from a trigger is to run it asynchronously and this can be achieved by executing a method with the @future method. 

Or You can call able to call Queueable apex also 
 
trigger LeadTrigger on Lead(before insert) {
if(Trigger.isBefore){
if(Trigger.isInsert){
System.enqueueJob(new QueueableExample(Trigger.New));
}
}
}



Or you can able to call bacth job also 


https://www.greytrix.com/blogs/salesforce/2014/10/30/invoke-future-methods-through-apex-trigger-for-web-service-callout/
https://harshitcoder.blogspot.com/2017/08/synchronous-and-asynchronous-apex.html
http://www.salesforcenextgen.com/asynchronous-apex/
https://blog.jeffdouglas.com/2013/04/04/why-the-force-com-future-annotation-should-die/
 
Ajay K DubediAjay K Dubedi
Hi Subodh,
The only way to execute a callout from a trigger is to run it asynchronously and this can be achieved by executing a method with the @future method. Future methods execute asynchronously i.e. one does not need to wait for a response:
TRIGGER:
        trigger ContactUpdate on Contact(after update){
        for(Contact con:trigger.new){
        ContactSynchrounselyUpdate.services(con.Id);
        }
        }
APEX-CLASS:
    public static void ContactSynchrounselyUpdate{
    @future(callout=true)
    public void services(String conId){
    /*
    */
    }
    }   
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi