Apex Invocable Actions

                       Let us discuss here how to use apex action. Action encapsulate a piece of logic that allows a user to perform some work, such as sending the email. Use actions to add more functionality to your applications. Choose from standard actions, such as posting to Chatter or sending email, or create actions based on your company’s needs. To run the apex invocable actions you need to use  InvocableMethod Annotation. Invocable methods are called with the REST API and used to invoke a single Apex method. Invocable methods have dynamic input and output values and support describe calls. The following code sample shows an invocable method with primitive data types. Represents a standard or custom invocable action.

Calling as an Apex Actions

Now you can able to call the apex class from the apex action using the rest API resource.use the following rest API resource.

Now login into the workbench and run the following rest API using the rest utils. This example invokes the Apex action called AccountQueryAction , 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 inputted.

Note The resource is the name of the Apex class, not the Apex method. 

here is the request body for the post method

After executing the rest API you can able to see the response as shown below.

Quick Notes 

  1. 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.
  2. 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.
  3. If an Apex action is used in a flow, packageable components that reference these elements aren’t automatically included in the package.
  4. 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.

Refer this links for more information on input and output variable support