InvocableVariable Annotation
To identify variables used by invocable methods in custom classes, use the InvocableVariable annotation.
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.
This code sample shows an invocable method with invocable variables.
This code sample shows an invocable method with invocable variables that have the generic sObject data type. Records for Input, yourDescription, and Records for Output are placeholder values.
All modifiers are optional.
Default values, labels, and placeholder text appear in Flow Builder for the Action element that corresponds to an invocable method. These modifiers help admins understand how to use variables in the flow.
-
defaultValue: Provide a value to the action at runtime, if no value is provided then these default values are provided to the action at runtime. Valid invocable variable data types are:
-
Boolean - fields must have a value of
'true'or'false'and case-insensitive. -
Decimal - fields must have a value of
'validDecimalValue'where the floating point value can’t have a suffix. -
Double - fields must have a value of
'validDoubleValue'where the d suffix is required and case-insensitive. -
Integer - fields must have a value of
'validIntegerValue'where the integer value can’t have a suffix. -
Long - fields must have a value of
'validLongValue'where the l suffix is required and case-insensitive. -
String - fields can use any valid string value including the empty string.
-
-
description: The description for the variable. The default is
Null. -
label: The label for the variable. The default is the variable name.
-
placeholderText: Provides examples or additional guidance about the invocable variable, such as examples of values that can set the invocable variable. Valid invocable variable data types are:
- Double - fields must have a value of
'validDoubleValue'where the d suffix is required and case-insensitive. - Integer - fields must have a value of
'validIntegerValue'where the integer value can’t have a suffix. - String - fields can use any valid string value including the empty string.
- Double - fields must have a value of
-
required: Specifies whether the variable is required. If not specified, the default is
false. The value is ignored for output variables.The
defaultValuemodifier throws an error when used withrequired.
The invocable variable annotation supports the modifiers shown in this example. The values yourLabel, yourDescription, and yourPlaceholderText are placeholders.
The invocable variable annotation supports defaultValue in this example, where yourDefaultValue is a placeholder.
-
Other annotations can’t be used with the
InvocableVariableannotation. -
Only
globalandpublicvariables can be invocable variables. -
The invocable variable can’t be any of these:
- A non-member variable such as a
staticorlocalvariable. - A property.
- A
finalvariable. Protectedorprivate.
- A non-member variable such as a
-
The data type of the invocable variable must be one of these:
- A primitive other than Object
- An sObject, either the generic sObject or a specific sObject
- A list of primitives, sObjects, or objects created from Apex classes
- A list of lists of primitives or objects created from Apex classes
-
The invocable variable name in Apex must match the name in the flow. The name is case-sensitive.
-
For managed packages:
- Public invocable variables can be set in flows and processes within the same managed package.
- Global invocable variables can be set anywhere in the subscriber org. Only global invocable variables appear in Flow Builder and Process Builder in the subscriber org.
-
Starting in API version 66.0, Apex classes used for invocable action parameters must have a visible no-argument constructor. Use the default constructor or add your own constructor. The constructor must be public for non-packaged classes or global for packaged classes invoked from outside the package. See Using Constructors.
See Also