Activity Forums Salesforce® Discussions Can a trigger make a call to Salesforce Apex callout method?

  • Anurag

    Member
    July 27, 2018 at 12:47 pm

    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”.

  • Parul

    Member
    September 14, 2018 at 4:59 am

    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

  • shariq

    Member
    September 15, 2018 at 2:06 pm

    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.

Popular Salesforce Blogs

Popular Salesforce Videos