I have 2 questions

  1. Can salesforce webservice call another web service? If yes does the webserice needs to be marked as future method?

  2. Can I Call static salesforce webservice from trigger how does itbehave? What happens if call future method from it.

1 Answer 1

  1. A web service inside salesforce can:

    • Execute the methods in the callout directly if within the same salesforce org. If the method does not use any of the request headers you can call the method directly
    • Make a callout to another webserive - does not need to be marked as @future
  2. You can call a static method in a restResource annotated method just like any other class. The only caveat is that the method cannot use or reference anything in the RestContext or RestReponse classes as they would be unavailable from a trigger...The annotation just allows the method to be mapped as a rest resource available to external systems

Basically treat it like any other static method, unless it utilizes the Rest classes in the method then you would treat it like any other callout

Consider this example:

global class myTestRest{

global static string myMethod(ID i){
     Account a = [Select Name From Account Where ID = :i];
     return a.name;


you would simply use mytestRest.myMethod(<AN ACCOUNT ID>); in your trigger directly

However if this line exists in your method:

RestRequest req = RestContext.request;

Then you will not be able to call the method directly unless you account for the possibility that RestContext or req could be NULL everywhere it is used in the method. (I am not 100% sure if RestContext would dereference null error if called directly or if the RestContext.request would just return null)

  • For question 1 is it answer same? when the webservice is called from trigger? "Make a callout to another webservice does not need to be marked as @future"
    – Praneeth
    Aug 19, 2015 at 12:53
  • Making a callout? No needs to be @future - If you can execute the methods directly then no, just treat the restful method as a static class.....
    – Eric
    Aug 19, 2015 at 13:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .