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
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:
@RestResource(URLMapping='/test/*')
global class myTestRest{
@HTTPPost
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)