+ Start a Discussion
Anil Ganivada 4Anil Ganivada 4 

Callout on apex trigger before insert

Hi,

  I need to make a callout to a webservice to update the content before it is saved using a trigger. Currently I am using "After insert" to get the id of the object and call an async class which would then update the object based on the response from web service. However I would like to change this behavior to before insert in which case the id of the object is returned as null since the object is not saved yet Is there any way I could do this ?

Thanks,
Anil
sfdcfoxsfdcfox
No, as callouts are not currently allowed from triggers at all. You could build a Visualforce page and override the new record button, but that won't apply to bulk loads (e.g. import wizard, data loader).
Amit Chaudhary 8Amit Chaudhary 8
Hi Anil,

Please try to use future method in trigger for callout.

You won't be able to make the callout synchronously from the trigger, because you would be holding up the transaction (and thus locking records etc) for a potentially long period of time.
Below post will help you
http://www.greytrix.com/blogs/salesforce/2014/10/30/invoke-future-methods-through-apex-trigger-for-web-service-callout/

Please let us know if this will help you
Thanks
Amit Chaudhary