Example: Generic SObject Input for Invocable Actions
This example creates a custom property editor for an invocable action that uses a generic sObject input parameter. An invocable action is an Apex method that you can add to your flow. In Flow Builder, an admin uses picklist fields to set the invocable action’s input parameters: the object of the record variable, the record variable, and the object for storing the output. When users run a flow for this example, the invocable action stores the first record from a collection of records.
This Apex class file defines the selectRecord
method that can run as an invocable action and its input variables. The @InvocableMethod
annotation identifies the method that can run as an invocable action. The @InvocableVariable
annotation identifies the variables used by the invocable method.
The invocable method registers the custom property editor in the configurationEditor
modifier. The namespace is c
unless the org has a custom namespace. If the org has a custom namespace, use that namespace to register the custom property editor. For this example, the name of the custom property editor is c-select-record-editor
.
These HTML, CSS, JavaScript, and configuration files define the custom property editor for the action.
The HTML template defines the UI for the custom property editor in Flow Builder.
This example shows the custom property editor UI.
When the custom property editor is initialized, the JavaScript class receives a copy of the flow metadata from Flow Builder. When the admin changes a value in the custom property editor, the custom property editor dispatches an event to propagate the change back to Flow Builder.
Use @api
properties to capture data from flows. Use events to report changes to flows at run time.
Flow Builder has a JavaScript interface for communicating with a custom property editor. This JavaScript class uses the inputVariables
, builderContext
, and genericTypeMappings
interfaces.
When the custom property editor is initialized, inputVariables
receives the values of the input variables in the invocable action from Flow Builder.
The inputVariables
data structure includes the name, value, and data type for each input variable.
The get inputValue()
method gets the value for each input variable for use in the custom property editor.
The genericTypeMappings
interface receives the values of the input variables that are generic sObject data types in the invocable action from Flow Builder.
The data structure includes the name and value for each input. The typeName
must match the name of the generic sObject input that is defined with the @InvocableVariable
annotation in the method for example ’T__inputCollection’
. T__
is prepended to input names and U__
is prepended to output names automatically . The typeValue
is the specific value for the generic sObject input for example Account
.
The get inputType()
and get outputType()
methods get the value for each input parameter that is a generic sObject data type for use in the custom property editor.
The get typeOptions()
method gets the labels and values for each object input option for use in the custom property editor.
The builderContext
interface provides data about the elements and resources in the flow.
The builderContext
data structure includes the elements and resources in the flow.
The get valueOptions()
method uses the data from variables as options for input values on the custom property editor for the invocable action’s input parameters.
When an admin enters a value for Object for Record Variable in the custom property editor, the handleInputTypeChange
method dispatches a configuration_editor_generic_type_mapping_changed
event to Flow Builder. Flow Builder receives the event and updates the value in the flow.
When an admin enters a value for Object for Storing Output in the custom property editor, the handleOutputTypeChange
method dispatches a configuration_editor_generic_type_mapping_changed
event to Flow Builder. Flow Builder receives the event and updates the value in the flow.
When an admin enters a value for Record Variable in the custom property editor, the handleValueChange
method dispatches a configuration_editor_input_value_changed
event to Flow Builder. Flow Builder receives the event and updates the value in the flow.
Here’s the configuration file for selectRecordEditor
.
See Also