... 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:
public class InvocableClass {
@InvocableMethod
public static List<Account> InsertAccount(List <String> names) {
List<Account> myAccounts = new List<Account>();
for (String accName: names)
{
Account acc = new Account(Name = accName);
myAccounts.add(acc) ;
}
insert myAccounts;
return myAccounts;
}
}
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:
{
"inputs" : [ {
"names" : "v1"
},
{
"names" : "v2"
}]
}
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:
{
"description" : null,
"inputs" : [ {
"byteLength" : 0,
"description" : null,
"label" : "Account",
"maxOccurs" : 1,
"name" : "Account",
"picklistValues" : null,
"required" : false,
"sobjectType" : null,
"type" : "STRING"
} ],
"label" : "InvocableClass",
"name" : "InvocableClass",
"outputs" : [ {
"description" : null,
"label" : "output",
"maxOccurs" : 1,
"name" : "output",
"picklistValues" : null,
"sobjectType" : "Account",
"type" : "SOBJECT"
} ],
"standard" : false,
"targetEntityName" : null,
"type" : "APEX"
}
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 :)
@InvocableMethod
when it didn't work?