Is there any documentation available related to @InvocationMethod annotation of APEX (Spring 15 feature)? I've been going through the release notes -

http://releasenotes.docs.salesforce.com/spring15/spring15/release-notes/rn_forcecom_flow_apex.htm

http://releasenotes.docs.salesforce.com/spring15/spring15/release-notes/rn_apex_new_classes_methods.htm#invocablemethod

http://releasenotes.docs.salesforce.com/spring15/spring15/release-notes/rn_api_invocable_actions.htm#rn_api_invocable_actions

But to me it seems that we can pass Any Datatype into a method identified as @InvocationMethod, and it can accept Any number of parameters, but while I try to savea method with 2 parameters it returns following error:

Compile Error: Only one parameter is supported on invocable methods

Also, it only accepts List datatype parameter and only returns list type variable as well. is this a known Limitation or an Issue as well (and not documented anywhere) ?

  • Thats a rather complex datatype for a parameter in this case :-)... As stated my intention is to make a function call from Process Builder's APEX Action. I was hoping to pass multiple parameters with multiple field values for the invoke call via Process Builder. – VarunC Jan 17 '15 at 21:18
  • Hi VarunC, you are right seems like only 1 parameter is allow however process builder UI allows to set more than one. At the moment as you commented only List that contain primitive types are allowed. I have a case with SF support, hopefully we will get some answers soon. I'll keep you update. I have also another question posted related with @InvocableMethod salesforce.stackexchange.com/questions/64116/… – Carolina Jan 22 '15 at 18:02
  • Thanks for the info @Carolina. Looking forward to your case updates :-), the Process builder allowing more than 1 parameter and InvocableMethod only accepting 1 parameter is kind of all the way confusing :) – VarunC Jan 23 '15 at 6:49
  • Thanks to you! Yes I know, I'm thinking that maybe this is only the first stage and they will keep "opening" the functionality. Keep you posted with any news! :) – Carolina Jan 23 '15 at 10:16
  • 1
    VarunC, here there is another link with more helpful information: developer.salesforce.com/docs/atlas.en-us.apexcode.meta/… – Carolina Jan 23 '15 at 10:43
up vote 11 down vote accepted

While you can only pass one variable to @invocationmethod, you can use @invocablevariable in your custom class instead to permit multiple input variables from Process Builder.

Use the InvocableVariable annotation to identify variables used by invocable methods in custom classes.

The InvocableVariable annotation identifies a class variable used as an input or output parameter for an InvocableMethod method’s invocable action. If you create your own custom class to use as the input or output to an invocable method, you can annotate individual class member variables to make them available to the method.

Source: https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_InvocableVariable.htm

  • Thnx this link and info is much more accurate in defining the answer for my question. – VarunC Mar 6 '15 at 17:49

I think this could help us :) , new documentation:

  • Only one method in a class can have the InvocableMethod annotation.
  • Triggers can’t use invocable methods.
  • The invocable method must be static and public or global, and its class must be an outer class.
  • Other annotations can’t be used with the InvocableMethod annotation.
  • There can be at most one input parameter and its data type must be one of the following:

    A list of a primitive data type or a list of lists of a primitive data type – the generic Object type is not supported. A list of an sObject type or a list of lists of an sObject type – the generic sObject type is not supported. A list of a user-defined type, containing variables of the supported types and with the InvocableVariable annotation. Create a custom global or public Apex class to implement your data type, and make sure your class contains at least one member variable with the invocable variable annotation.

  • If the return type is not Null, the data type returned by the method must be one of the following: A list of a primitive data type or a list of lists of a primitive data type – the generic Object type is not supported. A list of an sObject type or a list of lists of an sObject type – the generic sObject type is not supported. A list of a user-defined type, containing variables of the supported types and with the InvocableVariable annotation. Create a custom global or public Apex class to implement your data type, and make sure your class contains at least one member variable with the invocable variable annotation.
You can use invocable methods in packages, but once you add an invocable method you can’t remove it from later versions of the package.

We can find here more help now: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_InvocableMethod.htm

(Still waiting to see why process builder allow us to set up more than one parameter though )

Thanks, Carolina.

  • Thanks @Carolina for the link and this detailed explanation. Its nice to find this added to regular documentation. I'm marking this as Answer since to anyone finding the question, it can direct them to online docs for the answer to the query :-) ... – VarunC Jan 23 '15 at 13:48

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.