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
AjjuAjju 

can we do a Callout from with in a Trigger ?

thisisnotaprilthisisnotapril
Hi Ajju, you need to spend some time looking over the training materials we have on this site. https://developer.salesforce.com/page/Wiki
Ashish_SFDCAshish_SFDC
Hi Ajay, 


Callout is a ASynchronous process where as Trigger is Dynamic / Synchrinous. 

That means it is not directly possible to do a webservice  callout from a triiger. 

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:
http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_classes_annotation.htm?SearchType=Stem 

Mentioned in the idea: https://success.salesforce.com/ideaview?id=087300000007LfiAAE

A related thread, 

Callout from triggers are currently not supported.

https://developer.salesforce.com/forums?id=906F00000008wVrIAI


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, please read the documentation.

Main Doc: Apex Web Services and Callouts
https://developer.salesforce.com/page/Apex_Web_Services_and_Callouts


Regards,
Ashish
DazedPuzzledDazedPuzzled
yes You can. It is same as usual  class method calling  from trigger. The only difference being the method should always be asynchronous with @future
PV TPV T
Yes we can do callout from trigger but have to use future method. If anyother info required regarding the same let me know.
Pratik Raut 14Pratik Raut 14
Yes, you can.
Ahmed Ansari 13Ahmed Ansari 13
Yes , You can using  @future(callout=true) with callout method to call it in trigger

Regards,
Ahmed Ansari

​​​​​​​