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

Available in: Lightning Experience
Available in: Developer, Enterprise, Professional, and Unlimited editions for Industries clouds where Context Service is enabled

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

Dynamic Invocable Actions
Invocable action Description Input Values

Build Context Instance Dynamically

Builds a context instance of a context definition with an Apex-defined input.

Context Record Data (optional): The Apex-defined variable containing the records to build the context instance. Specify the ID and businessObjectType for each node to hydrate.

Context Mapping ID (optional): The name or ID of the context mapping record.

Add Context Records Dynamically

Adds or overwrites records in a context instance with an Apex-defined input.

Context ID (required): The ID of the context instance in which to add or overwrite records.

Context Record Data (required): The Apex-defined variable containing the records to add.

Overwrite Existing Records (optional): Whether to overwrite existing records. The default is False.

Query Context Records Dynamically

Queries records in an existing context instance with an Apex-defined output.

Context ID (required): The ID of the context instance to query.

Query Paths (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).

Context Mapping ID (optional): The name or ID of the context mapping record.

Update Context Attributes Dynamically

Updates the context attributes from an instance of a context definition with an Apex-defined input.

Context ID (required): The ID of the context instance to update.

Context Record Data (required): The Apex-defined variable containing the records with updated attribute values. Populate dataPath on each node variable to identify which record to update.

Query Context Tags Dynamically

Queries the dynamic context tags from a context instance and returns the results as an Apex-defined output.

Context ID (required): The ID of the context instance to query.

Tag List (required): A collection of tag names to query.

Output Values for Dynamic Invocable Actions

Output Values for Dynamic Invocable Actions
Invocable action Output Values

Build Context Instance Dynamically

Context ID: The unique identifier of the built context instance. Use this ID in subsequent actions to query, update, or add records.

Context Definition: The ID or developer name of the context definition.

Context Mapping: The context mapping ID or name used to build the instance.

Add Context Records Dynamically

No output parameters. Records are added to the existing context instance identified by the Context ID input.

Query Context Records Dynamically

Apex-Defined Output: A populated instance of the Definition Root class containing the queried records in the generated Apex class structure.

Update Context Attributes Dynamically

No output parameters. Attributes are updated in the existing context instance identified by the Context ID input.

Query Context Tags Dynamically

Query Tag Results: 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.

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:

Meta Attributes
Meta Attribute Purpose When to Set

id

The Salesforce record ID

Build Context: specify which record to hydrate. Add Records: identify existing parent.

businessObjectType

The sObject API name

Build Context: specify the object type for hydration.

dataPath

Unique path to a record in the context cache

Update Context: identify which specific record to modify.

dmlStatus

Result of Data Manipulation Language (DML) operation

Read-only. Populated after Persist Context Data.

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