I've been trying to use the new Spring '15 functionality related to Invocable Actions / @InvocableMethod
/ @InvocableVariable
using the current documentation:
https://www.salesforce.com/us/developer/docs/api_rest/
http://releasenotes.docs.salesforce.com/spring15/spring15/release-notes/rn_forcecom_flow_apex.htm
I'm wondering how it would be possible to execute the method through the REST API as the documentation says.
I am able to get a response when I use the following call through Workbench or Hurl:
https://yourInstance.salesforce.com/services/data/v33.0/actions/custom/apex/InvocableClass
InvocableClass
is the apex class that contains my @InvocableMethod
.
The fun bit is that everything works ok when the @InvocableMethod
is executed through a Process built with Process Builder.
Why?
Thanks for your help in advance!
PS: I have a support case meanwhile with SF as I couldn't find any solution at the moment.
Best Answer
... and here it is the way to do it:
To be able to execute the
@InvocableMethod
that is in the class, this method needs to have the one permitted parameter. If the method is defined without the parameter then this is not executed, since the REST API doesn't have enough information to know what needs to be executed / invoked.Therefore this is the way to implement the
@InvocableMethod
and the corresponding call:Through workbench we will do a POST call to:
/services/data/v33.0/actions/custom/apex/InvocableClass
In the body we could do something like:
Using the same call, we could change the
@InvocableMethod
in order to do a query within it.If instead of executing/invoking the method what we would like to get is the metadata, then we will do a GET call to the same URL and we will get a response like this one:
Note: if the method is defined without parameter it won't be invoked/ executed through REST :
public static void InsertAccount() //or public static List < Account > InsertAccount()
However through Process Builder any definition is good and the method will be always invoked/executed :)