Newer Version Available

This content describes an older version of this product. View Latest

Apex Actions

Invoke Apex methods annotated with @InvocableMethod and include custom parameters with @InvocableVariable.

This object is available in API version 33.0 and later.

Supported REST HTTP Methods

URI
Get a list of available Apex actions:
/vXX.X/actions/custom/apex
Get information about a specific Apex action:
/vXX.X/actions/custom/apex/action_name
Formats
JSON, XML
HTTP Methods
GET, HEAD, POST
Authentication
Authorization: Bearer token
Parameters
None
Example
This example invokes the Apex action called ActionTest, which takes a list of IDs and returns a list of associated account names. The top-level key name in the JSON request body must be inputs.
1POST /vXX.X/actions/custom/apex/ActionTest
2
3{
4   "inputs":[
5      {
6         "ids":"001d0000023BBAoAAO"
7      },
8      {
9         "ids":"001d0000026ChP1AAK"
10      },
11      {
12         "ids":"001d000001tYHulAAG"
13      }
14   ]
15}
Here is the Apex code:
1public class ActionTest {
2  
3  @InvocableMethod(label='Action Test' description='Given a list of Account IDs, return a list of Account names.')
4
5  public static List<String> getAccountNames(List<ID> ids) {
6
7     List<String> accountNames = new List<String>();
8     Account a = new Account();
9
10     for (ID id : ids) {
11         a = [SELECT Name FROM Account WHERE Id = :id];
12         accountNames.add(a.Name);
13     }
14
15    return accountNames;
16  }
17}

The resource is the name of the Apex class, not the Apex method. In this example, the resource is /ActionTest, not /getAccountNames.

Note

Notes
  • Describe and invoke for an Apex action respect the profile access for the Apex class. If you don’t have access, an error is issued.
  • If you add an Apex action to a flow, and then remove the @InvocableMethod annotation from the Apex class, you get a run-time error in the flow.
  • If an Apex action is used in a flow, packageable components that reference these elements aren’t automatically included in the package. For example, if you use an email alert, you must manually add the email template that is used by that email alert. To deploy the package successfully, manually add those referenced components to the package.
  • An Apex invocable action can be declared public or global in a managed package. However, that action doesn’t appear in the Cloud Flow Designer’s list of available actions while building or editing a flow. These invocable actions can still be referred to by flows within the same managed package. Global Apex invocable actions in a managed package can be used in flows outside the managed package, anywhere in the organization, and appear in the Cloud Flow Designer’s list of available actions to add to a flow.

Inputs

Supply input values that correspond to the Apex action.

  • A POST request body must use the JSON format specified in Invoking Actions.
  • Apex methods annotated with @InvocableMethod must take a List as an input and return a List or Null. For more information, see @InvocableMethod Annotation in the Apex Developer Guide.
  • Only the following primitive types are supported as inputs in a POST request body:
    • Blob
    • Boolean
    • Date
    • Datetime
    • Decimal
    • Double
    • ID
    • Integer
    • Long
    • String
    • Time

For more information, see the @InvocableMethod and @InvocableVariable annotations in the Apex Developer Guide.

Outputs

The Apex InvocableMethod determines the output values.