---
schema_version: "1"
id: 446cb192704c1ed8f99daa85fd4ecb5cc00b1410e27a92f6cafd49719b97509a
title: Dynamic Context Service Invocable Actions
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/ind/264-0-0/ctx_dynamic_invocable_actions.md
canonical_url: https://help.salesforce.com/s/articleView?id=ind.ctx_dynamic_invocable_actions.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 50aad47a09507b8a715937f851f7b9a5359d3e992940ef3f5281af6b28a1d4ea
description: 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.
products:
  - Industry Solutions
  - Cross Cloud
release: "264"
---
# Dynamic Context Service Invocable Actions

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.

### 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>

Unlike standard invocable actions that use JSON strings for input and output, dynamic actions provide type-safe data handling based on your context definition's generated Apex classes. Use dynamic actions when you want structured data handling directly in Flow Builder without JSON manipulation. Use standard actions when working with JSON data, when you haven't generated an Apex class, or when working with dynamic attributes from the context dictionary that aren't included in generated classes.

To use dynamic invocable actions, first generate an Apex class from the context definition.

## Available Dynamic Invocable Actions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small " summary="Dynamic Invocable Actions">
        <caption>Dynamic Invocable Actions</caption>
        <colgroup>
          <col style="width:22.22222222222222%">
          <col style="width:33.33333333333333%">
          <col style="width:44.44444444444444%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d3363e89">Invocable action</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d3363e92">Description</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d3363e95">Input Values</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Invocable action" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e89 ">
              <p style="margin-bottom:0;">Build Context Instance Dynamically</p>
            </td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e92 ">
              <p style="margin-bottom:0;">Builds a context instance of a context definition with an Apex-defined
                input.</p>
            </td>

            <td data-label="Input Values" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e95 ">
              <p><strong class="uicontrol">Context Record Data</strong> (optional): The Apex-defined variable
                containing the records to build the context instance. Specify the ID and
                businessObjectType for each node to hydrate.</p>
              <p style="margin-bottom:0;"><strong class="uicontrol">Context Mapping ID</strong> (optional): The name or ID of the
                context mapping record.</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="Invocable action" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e89 ">
              <p style="margin-bottom:0;">Add Context Records Dynamically</p>
            </td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e92 ">
              <p style="margin-bottom:0;">Adds or overwrites records in a context instance with an Apex-defined
                input.</p>
            </td>

            <td data-label="Input Values" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e95 ">
              <p><strong class="uicontrol">Context ID</strong> (required): The ID of the context instance
                in which to add or overwrite records.</p>
              <p><strong class="uicontrol">Context Record Data</strong> (required): The Apex-defined
                variable containing the records to add.</p>
              <p style="margin-bottom:0;"><strong class="uicontrol">Overwrite Existing Records</strong> (optional): Whether to
                overwrite existing records. The default is False.</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="Invocable action" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e89 ">
              <p style="margin-bottom:0;">Query Context Records Dynamically</p>
            </td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e92 ">
              <p style="margin-bottom:0;">Queries records in an existing context instance with an Apex-defined
                output.</p>
            </td>

            <td data-label="Input Values" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e95 ">
              <p><strong class="uicontrol">Context ID</strong> (required): The ID of the context instance
                to query.</p>
              <p><strong class="uicontrol">Query Paths</strong> (required): A collection of data paths to
                the records to be queried. Paths follow the hierarchical relationship separated
                by forward slashes (for example, AccountId/ContactId/OpportunityId).</p>
              <p style="margin-bottom:0;"><strong class="uicontrol">Context Mapping ID</strong> (optional): The name or ID of the
                context mapping record.</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="Invocable action" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e89 ">
              <p style="margin-bottom:0;">Update Context Attributes Dynamically</p>
            </td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e92 ">
              <p style="margin-bottom:0;">Updates the context attributes from an instance of a context definition with
                an Apex-defined input.</p>
            </td>

            <td data-label="Input Values" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e95 ">
              <p><strong class="uicontrol">Context ID</strong> (required): The ID of the context instance
                to update.</p>
              <p style="margin-bottom:0;"><strong class="uicontrol">Context Record Data</strong> (required): The Apex-defined
                variable containing the records with updated attribute values. Populate
                dataPath on each node variable to identify which record to update.</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="Invocable action" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e89 ">
              <p style="margin-bottom:0;">Query Context Tags Dynamically</p>
            </td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e92 ">
              <p style="margin-bottom:0;">Queries the dynamic context tags from a context instance and returns the results
                as an Apex-defined output.</p>
            </td>

            <td data-label="Input Values" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e95 ">
              <p><strong class="uicontrol">Context ID</strong> (required): The ID of the context instance
                to query.</p>
              <p style="margin-bottom:0;"><strong class="uicontrol">Tag List</strong> (required): A collection of tag names to
                query.</p>
            </td>

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

## Output Values for Dynamic Invocable Actions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small " summary="Output Values for Dynamic Invocable Actions">
        <caption>Output Values for Dynamic Invocable Actions</caption>
        <colgroup>
          <col style="width:33.33333333333333%">
          <col style="width:66.66666666666666%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d3363e276">Invocable action</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d3363e279">Output Values</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Invocable action" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e276 ">
              <p style="margin-bottom:0;">Build Context Instance Dynamically</p>
            </td>

            <td data-label="Output Values" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e279 ">
              <p><strong class="uicontrol">Context ID</strong>: The unique identifier of the built context
                instance. Use this ID in subsequent actions to query, update, or add
                records.</p>
              <p><strong class="uicontrol">Context Definition</strong>: The ID or developer name of the
                context definition.</p>
              <p style="margin-bottom:0;"><strong class="uicontrol">Context Mapping</strong>: The context mapping ID or name used to
                build the instance.</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="Invocable action" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e276 ">
              <p style="margin-bottom:0;">Add Context Records Dynamically</p>
            </td>

            <td data-label="Output Values" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e279 ">
              <p style="margin-bottom:0;">No output parameters. Records are added to the existing context instance
                identified by the Context ID input.</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="Invocable action" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e276 ">
              <p style="margin-bottom:0;">Query Context Records Dynamically</p>
            </td>

            <td data-label="Output Values" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e279 ">
              <p style="margin-bottom:0;"><strong class="uicontrol">Apex-Defined Output</strong>: A populated instance of the
                Definition Root class containing the queried records in the generated Apex class
                structure.</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="Invocable action" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e276 ">
              <p style="margin-bottom:0;">Update Context Attributes Dynamically</p>
            </td>

            <td data-label="Output Values" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e279 ">
              <p style="margin-bottom:0;">No output parameters. Attributes are updated in the existing context instance
                identified by the Context ID input.</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="Invocable action" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e276 ">
              <p style="margin-bottom:0;">Query Context Tags Dynamically</p>
            </td>

            <td data-label="Output Values" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e279 ">
              <p style="margin-bottom:0;"><strong class="uicontrol">Query Tag Results</strong>: A populated instance of the
                Definition Root class containing the queried tag data mapped to Apex attribute
                names. Assign this output manually in the action's Advanced section.</p>
            </td>

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

## How Dynamic Actions Use Apex Classes

The Definition Root class (<DefinitionName>\_DefRoot) serves as the main input and output container for all dynamic invocable actions:

- For write actions (Build, Add Records, Update), you build the data hierarchy within a root variable and pass it to the action's Apex-Defined Input parameter.
- For read actions (Query Records, Query Tags), you receive a populated root variable as output and iterate through its node collections.

Each node class contains the node's attributes plus these meta-attributes:

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small " summary="Meta Attributes">
        <caption>Meta Attributes</caption>
        <colgroup>
          <col style="width:22.22222222222222%">
          <col style="width:33.33333333333333%">
          <col style="width:44.44444444444444%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d3363e425">Meta Attribute</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d3363e428">Purpose</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d3363e431">When to Set</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Meta Attribute" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e425 ">
              <p style="margin-bottom:0;">id</p>
            </td>

            <td data-label="Purpose" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e428 ">
              <p style="margin-bottom:0;">The Salesforce record ID</p>
            </td>

            <td data-label="When to Set" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e431 ">
              <p style="margin-bottom:0;">Build Context: specify which record to hydrate. Add Records: identify existing
                parent.</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="Meta Attribute" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e425 ">
              <p style="margin-bottom:0;">businessObjectType</p>
            </td>

            <td data-label="Purpose" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e428 ">
              <p style="margin-bottom:0;">The sObject API name</p>
            </td>

            <td data-label="When to Set" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e431 ">
              <p style="margin-bottom:0;">Build Context: specify the object type for hydration.</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="Meta Attribute" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e425 ">
              <p style="margin-bottom:0;">dataPath</p>
            </td>

            <td data-label="Purpose" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e428 ">
              <p style="margin-bottom:0;">Unique path to a record in the context cache</p>
            </td>

            <td data-label="When to Set" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e431 ">
              <p style="margin-bottom:0;">Update Context: identify which specific record to modify.</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="Meta Attribute" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e425 ">
              <p style="margin-bottom:0;">dmlStatus</p>
            </td>

            <td data-label="Purpose" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e428 ">
              <p style="margin-bottom:0;">Result of Data Manipulation Language (DML) operation</p>
            </td>

            <td data-label="When to Set" class="slds-cell-wrap" style="vertical-align:top;" headers="d3363e431 ">
              <p style="margin-bottom:0;">Read-only. Populated after Persist Context Data.</p>
            </td>

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

## Input Strategy for Build Context and Add Records

For actions that write data, establish the parent-child relationship within your Apex variables before passing the root object to the action.

To link a child node (such as Contact) to a parent node (such as Account):

- Create Apex-defined variables for both the child and parent nodes.
- Assign attribute values to the child variable (such as LastName and id).
- Add the child variable to the parent variable's child collection (for example, add ContactApex to AccountApex.Contact).
- Add the parent variable to the root variable (for example, add AccountApex to ApexIP.Account).
- Pass the completed root variable to the action's **Context Record Data** parameter.

![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 When adding records to an existing parent in the context instance, assign the existing parent's record ID to the parent variable's id attribute. This tells the service which parent to attach the new child to.

## Output Strategy for Query Actions

When querying records or tags, the output is a populated instance of the Definition Root class.

- Node references are always returned as collections (Lists). Use a Loop element in your flow to access individual records, even when you expect only one record.
- Access attribute values by using the Apex attribute names (for example, item.BillingCity), not the context tag names, because tags aren't available in the generated Apex class.
- Even deeply nested nodes (such as Opportunity under Contact under Account) can be accessed directly from the root class as a collection.
- When querying a parent record, its direct children are included in the same output object.

- **[Work with Dynamic Invocable Action Data in Flows](https://help.salesforce.com/s/articleView?id=ind.ctx_work_with_dynamic_invocable_action_data.htm&release=264.0.0&type=5)**  
    Set up the Apex-defined variables that dynamic invocable actions require as input, and process the Apex-defined output that query actions return.

#### See Also

- [Apex-Defined Data Type](https://help.salesforce.com/s/articleView?id=platform.flow_concepts_apex_type.htm&language=en_US)
- [Considerations for the Apex-Defined Data Type](https://help.salesforce.com/s/articleView?id=platform.flow_considerations_apex_data_type.htm&language=en_US)
- [Apex Classes for a Context Definition](https://help.salesforce.com/s/articleView?id=ind.ctx_apex_classes_for_context_definitions.htm&release=264.0.0&type=5 "Apex classes provide the framework for the structure and data of a context definition. You can use these classes to create and manage the context data in your Salesforce org.")