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);
}
}
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
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:- Class:-
Thanks
Anil.B
Or You can call able to call Queueable apex also
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/
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: I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi