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

Calling a Web Service using Trigger


Can we call a web service class using a trigger?please provide me with some examples as i am new to apex and just trying to explore it..


Any help in this regard is kindly appreciated.





Pratibh PrakashPratibh Prakash



Webservice cannot be called directly from a trigger.

There is special type of method called as future method,  declared using future annotation as:


@future (callout= true)

public static void sampleMethod()


The speciality of this method is that it accepts only primitive data type as arguments i.e. String, Double /List or Set of the same and arguments such a Account, Contact or any collection of the same is not accepted.


So the webservice callout logic needs to placed in a future method and the future method needs to be called from the trigger.


Future method execute in different context that is why we can make callout, it does execute in same context as trigger i.e. asynchronous.