Work with Dynamic Invocable Action Data in Flows

Set up the Apex-defined variables that dynamic invocable actions require as input, and process the Apex-defined output that query actions return.

Required Editions

Available in: Lightning Experience
Available in: Developer, Enterprise, Professional, and Unlimited editions for Industries clouds where Context Service is enabled
User Permissions Needed
To create a flow: Manage Flow
To invoke context service actions:

Context Service Admin

OR

Context Service Runtime

Before you begin, generate an Apex class for your context definition.

  1. Prepare input for the Build Context Instance Dynamically action.
    1. In your flow, create an Apex-defined variable for each node you want to hydrate. Set the Apex class to the node class from your context definition (for example, SalesContextDef_Account).
    2. Use an Assignment element to set the node variable's id attribute to the Salesforce record ID you want to fetch. Set businessObjectType to the object API name (for example, Account).
    3. If the node has child records to hydrate, create variables for the child nodes. Add each child variable to the parent variable's child collection (for example, add ContactApex to AccountApex.Contact).
    4. Create an Apex-defined variable for the Definition Root class (for example, SalesContextDef_DefRoot).
    5. Add your node variables to the corresponding collections in the root variable (for example, add AccountApex to RootVar.Account).
    6. In the Build Context action, set the Apex-Defined Input Object parameter to your root variable.
  2. Prepare input for the Add Context Records Dynamically action.
    1. Create an Apex-defined variable for the child node you want to add (for example, SalesContextDef_Opportunity).
    2. Use an Assignment element to set attribute values on the child variable.
    3. Create an Apex-defined variable for the parent node where you want to attach the new child.
    4. Set the parent variable's id attribute to the existing parent record's ID in the context instance.
      Important
      Important You must set the parent's id to identify which existing parent record to attach the child to.
    5. Add the child variable to the parent variable's child collection (for example, add OpportunityApex to ContactApex.Opportunity).
    6. Create an Apex-defined variable for the Definition Root class and add the parent variable to it.
    7. In the Add Context Records action, set Context Record Data to your root variable.
  3. Prepare input for the Update Context Attributes Dynamically action.
    1. Create an Apex-defined variable for the node containing the attributes you want to update (for example, SalesContextDef_Account).
    2. Set the dataPath attribute on the node variable to identify which specific record in the context cache to update.
      Important
      Important The dataPath is required to target a specific record. If you previously queried the context instance, the dataPath value is available in the query results.
    3. Assign new values to the attributes you want to change (for example, set AccountApex.BillingCity to your new value).
    4. Create an Apex-defined variable for the Definition Root class and add the updated node variable to it.
    5. In the Update Context Attributes action, set Context Record Data to your root variable.
  4. Prepare input for the Query Context Records Dynamically action.
    1. Create a collection variable of type Text to hold your query paths.
    2. Use an Assignment element to add data path strings to the collection. Format each path as the hierarchical relationship separated by forward slashes (for example, AccountRecordId/ContactRecordId).
    3. In the Query Context Records action, set Query Paths to your path collection variable.
  5. Process output from query actions.
    1. Create an Apex-defined variable of the Definition Root type (for example, SalesContextDef_DefRoot) to receive query output.
    2. In the query action's output section (or the Advanced section for Query Tags), assign the result to your root variable.
    3. Add a Loop element to iterate through the node collection you want to access (for example, loop through RootVar.Account).
    4. Within the loop, access attribute values using the Apex property names (for example, currentItem.BillingCity).
Note
Note All node references are returned as collections. Use a Loop element even when you expect a single record. Access values using Apex attribute names, not context tag names.