Activity › Forums › Salesforce® Discussions › Can a trigger make a call to Salesforce Apex callout method?
-
Can a trigger make a call to Salesforce Apex callout method?
Posted by Sanjana on July 9, 2018 at 8:07 AMCan a trigger make a call to Salesforce Apex callout method?
shariq replied 7 years, 8 months ago 4 Members · 3 Replies -
3 Replies
-
Hi Sanjana,
There is only one way to make a callout from a trigger and that is to run it asynchronously by using a future method.The reason for it is that the apex trigger restricts database transaction until the callout is completed and the time limit for this is up to 120 seconds.Future methods execute asynchronously i.e. one does not need to wait for a response. Hence, it can be used. Also remember that in order to make a callout from an apex trigger through future method, we need to enable a callout from future by passing an extra parameter “Callout=true”.
- [adinserter block='9']
-
An Apex trigger can execute a callout when the callout is invoked within a method defined as asynchronous: that is, defined with the @future keyword. The @future annotation signifies that the Apex method executes asynchronously. For more information on the @future annotation.
Future methods execute asynchronously i.e. one does not need to wait for a response. The thing to keep in mind is, a future method can have native calls, as well as, they can make a call out to an external web service and hence, in order to enable the future method to allow callouts, an extra parameter “Callout=true” needs to be passed.
THanks
-
Hi,
Callout is a Asynchronous process where as Trigger is Dynamic / Synchronous.
That means it is not directly possible to do a webservice callout from a trigger.
But using @Future annotation we can convert the Trigger into a Asynchrinous Class and we can use a Callout method.
See the links below for some more information ,
You can invoke callouts from triggers by encapsulating the callouts in @future methods
Hope this helps.
Log In to reply.