---
schema_version: "1"
id: aeef483e27e299c9486c9bbaa04d487646ce8139a9c313bee076d2a9c9dcce32
title: Work with Dynamic Invocable Action Data in Flows
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/ind/264-0-0/ctx_work_with_dynamic_invocable_action_data.md
canonical_url: https://help.salesforce.com/s/articleView?id=ind.ctx_work_with_dynamic_invocable_action_data.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 7371174249dff7b001ff965319bfe0b3d9a5c47de47db639aebef6ef9b7aa1af
description: Set up the Apex-defined variables that dynamic invocable actions require as input, and process the Apex-defined output that query actions return.
products:
  - Industry Solutions
  - Cross Cloud
release: "264"
---
# 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

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: Lightning Experience</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: <strong>Developer</strong>, <strong>Enterprise</strong>, <strong>Professional</strong>, and <strong>Unlimited</strong> editions for Industries clouds where Context Service is enabled</td></tr></tbody></table>

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small permission">
        <colgroup>
          <col style="width:50%">
          <col style="width:50%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="colgroup" class="slds-cell-wrap" colspan="2" style="text-align:center;vertical-align:top;" id="d4471e74">User Permissions Needed</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d4471e74 ">To create a flow:</td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d4471e74 ">Manage Flow</td>

          </tr>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d4471e74 ">To invoke context service actions:</td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d4471e74 ">
              <p>Context Service Admin</p>
              <p>OR</p>
              <p style="margin-bottom:0;">Context Service Runtime</p>
            </td>

          </tr>
        </tbody>
      </table>

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](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-context_service-264-0-0-production-enus/e9dc37f3-cb53-4bc1-be8b-b6873099d0be/images/icon_important.png)
        
        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](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-context_service-264-0-0-production-enus/e9dc37f3-cb53-4bc1-be8b-b6873099d0be/images/icon_important.png)
        
        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](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-context_service-264-0-0-production-enus/e9dc37f3-cb53-4bc1-be8b-b6873099d0be/images/icon_note.png)

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.

#### See Also

- [Dynamic Context Service Invocable Actions](https://help.salesforce.com/s/articleView?id=ind.ctx_dynamic_invocable_actions.htm&release=264.0.0&type=5 "Manage your business application data efficiently by combining the capabilities of Salesforce Flow and Context Service dynamic invocable actions. With dynamic actions, you can work with typed Apex-defined variables that mirror your context definition structure.")
- [Call Dynamic Context Service Invocable Actions from Flows](https://help.salesforce.com/s/articleView?id=ind.ctx_call_dynamic_invocable_actions.htm&release=264.0.0&type=5 "Call invocable actions for context definitions that have Apex classes generated.")