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
Anil Ganivada 4Anil Ganivada 4 

Callout on apex trigger before insert


  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 ?

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

Please let us know if this will help you
Amit Chaudhary