# Execute Flow

## Overview

The Execute Flow interaction triggers a background process (an autolaunched Flow) from within a Dynamic Component. This is useful for automating tasks, updating records, performing calculations, or implementing any other logic in a Flow.

{% hint style="warning" %}

#### Important Note

The "**Execute Flow**" interaction is designed for *autolaunched* Flows (Flows that run in the background). If you want to launch a *Screen Flow* (a Flow with user interface elements), use the "[Open Flow Dialog](https://docs.avonnicomponents.com/dynamic-components/component-builder/interactions/flow-builder-integration/open-flow-dialog)" or "[Open Flow Panel](https://docs.avonnicomponents.com/dynamic-components/component-builder/interactions/flow-builder-integration/open-flow-panel)" interactions instead
{% endhint %}

***

## Configuration

Use these settings to connect your component to an Autolaunched Flow. This interaction runs background logic without opening any screens.

### **Flow Selection & Requirements**

Define which specific automation logic to trigger by specifying the Flow API Name.

* **What it is**: The unique identifier of the Flow you want to execute (e.g., `Create_Case_Records`).
* **Where to find it**: Open your Flow in Salesforce Flow Builder and check the Flow Properties (the gear icon) to view and copy the API Name.

### **Input Variables (Passing Data)**

Input variables serve as parameters, allowing you to send context (such as a Record ID) from your component into the Flow so it knows which data to process.

#### A. The Variable Name&#x20;

Enter the exact API name of the input variable as defined in your Flow.

* **Requirement**: The variable must be marked as "Available for Input" inside Salesforce Flow Builder.
* **Formatting**: This field is case-sensitive. It must match the Flow variable exactly (e.g., `recordId`, `accountName`, `opportunityStage`).

#### B. The Value&#x20;

Select the data you want to send into that variable. You can choose between two types of values:

* **Static Value**: Enter a fixed value directly. Use this for data that never changes regardless of user interaction.
  * *Examples:* `"Active"`, `100`, `true`, `"High Priority"`
* **Dynamic Value** (Mapped): Click the Map Icon to link the value to a dynamic source within your component. This allows the flow to react to the specific record or user selection. Common sources include:
  * **Record Fields**: Pass the ID or field value of the current record (e.g., `Record: Id`).
  * **Component Attributes**: Pass the state of another component (e.g., `Datatable.SelectedRows`).

| Value Type               | Description                                                       |
| ------------------------ | ----------------------------------------------------------------- |
| **Component Resource**   | Variables, queries, or formulas defined in your Dynamic Component |
| **Component Attributes** | Properties passed into your component                             |
| **Global Variables**     | System-wide values like current user or organization info         |
| **Selected Row Data**    | Data from a selected row in a Data Table                          |
| **Formulas**             | Calculated values or expressions                                  |

<mark style="background-color:green;">💡</mark> <mark style="background-color:green;"></mark><mark style="background-color:green;">**Tip**</mark>**:** Use the Mapped (x) icon whenever you need the value to be dynamic or come from your component's context. Use static values for constants that never change.

***

### Output Variables

Output variables capture data that the Flow returns after it finishes running. This allows your Flow to send results back to your Dynamic Component—such as newly created record IDs, calculated values, or status messages—which you can then use to update the UI or trigger additional actions.

#### **How output variables work**

* Each output variable you configure maps to a corresponding variable in your Flow
* The Flow variables must be marked as **"Available for Output"** in Flow Builder
* The returned data is stored in a Dynamic Component resource that you specify

#### **Configuring each output variable**

**Name**\
The exact API name of the output variable as defined in your Flow.

* Must match precisely (case-sensitive)
* Examples: `outputContentDocumentId`, `calculatedDiscount`, `errorMessage`

**Resource Name**\
The name of the Dynamic Component resource where the Flow's output will be stored.

* This must be a variable you've already created in your Dynamic Component
* The data type should match the type returned by the Flow (Text, Number, Boolean, Record, etc.).

**Example mappings**

* Flow outputs a Document ID → Store in: `contentDocumentId` (Text variable)
* Flow outputs a discount amount → Store in: `finalDiscount` (Number variable)
* Flow outputs success status → Store in: `wasSuccessful` (Boolean variable)

<mark style="background-color:green;">💡</mark> <mark style="background-color:green;"></mark><mark style="background-color:green;">**Tip:**</mark> Create your Dynamic Component variables before configuring the Execute Flow interaction, so they're available to select in the Resource Name field.

***

### On Finish

The On Finish configuration defines what happens after the Flow completes successfully. This is where you create a responsive user experience by providing feedback, updating the interface, or triggering follow-up actions.

***

## Step-by-Step Example

### Bulk Update Contact Status

This example demonstrates how to create a header action button in a Data Table that updates the status of selected Contact records to "Active" using an autolaunched Flow.

#### Scenario

You have a Data Table in your Dynamic Component displaying Contact records. You want to add a **"Set as Active"** button in the Data Table's header actions. When users select one or more Contact rows and click this button, the selected Contacts' status should automatically be set to "Active" via an autolaunched Flow.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FR4aMp6ajwf7CDtWllWFW%2F2025-11-13_13-16-09%20(1).gif?alt=media&#x26;token=c18bb43b-8b8f-4480-9e13-2e120ff1193d" alt=""><figcaption></figcaption></figure>

**What you'll build:**

* A Data Table showing Contact records with selectable rows
* A header action button labeled "Set as Active"
* An autolaunched Flow that updates the Status field
* An Execute Flow interaction that triggers when the button is clicked

{% stepper %}
{% step %}

#### **Create the Autolaunched Flow**

First, build the Flow that will handle the bulk status update in Salesforce

**Flow Setup**

1. In Salesforce Setup, go to **Flows** → **New Flow**
2. Select **Autolaunched Flow (No Trigger)** and click **Create**

**Flow Logic**

The Flow needs three key components:

1. **Input Variable (Collection):**
   * Name: `ContactIds`
   * Type: **Text Collection** (must allow multiple values)
   * **Critical:** This must be configured as a collection to receive multiple Contact IDs from the Data Table when users select multiple rows
   * This is what allows the Flow to process bulk updates rather than just a single record
2. **Update Records Element:**
   * Find Contacts where: `Id Is In {!ContactIds}`
   * Update field: `Status__c = "Active"`
   * This updates all selected Contact records in bulk

**Save and Activate**

* Save the Flow with a descriptive name (e.g., `Set_Contact_Status_Active`)
* **Activate** the Flow

***

**The key principle:** The Flow receives a collection of Contact IDs as input, finds all matching Contact records, and updates their Status field to "Active".
{% endstep %}

{% step %}

#### Configure Your Data Table in the Dynamic Component

Now that your Flow is created and activated, switch to configuring your Dynamic Component where the Data Table will display Contact records.

**Where you are:** In the Dynamic Component builder (not in Flow Builder anymore)

Set up your Data Table to display Contacts with row selection enabled:

1. **Select your Data Table component** in the Dynamic Component
2. **Configure the data source and columns:**
   * Ensure your Data Table is connected to a Query resource that retrieves Contact records
   * Add columns to the Data Table by selecting the fields you want to display (e.g., `Name`, `Status__c`, `Email`)
3. **Enable multiple row selection:**
   * In the Data Table properties, locate the **Max Row Selection** attribute
   * Make sure it's **not set to 1** to allow users to select multiple records on the Data Table
   * This ensures users can bulk update multiple Contacts at once.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2Fj51tpWZmzDFjRWj9tybq%2F2025-11-13_20-37-16.png?alt=media&#x26;token=79b96f46-dd9f-4902-af10-75972e6469e9" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### Add the Header Action Button

Add the "Set as Active" button to your Data Table's header:

1. **With your Data Table selected**, navigate to the **Header** section in the properties panel
2. **Click "Add Header Action"**
3. **Configure the button:**
   * **Label:** `Set as Active`
   * **Icon (optional):** `utility:check`
   * **Type:** Button

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FHoi1gGPNmqmmkEe3Fhm2%2F2025-11-13_20-38-11.png?alt=media&#x26;token=c1d2f78c-5bbf-4e88-8a33-dff467f8176a" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### Configure the Execute Flow Interaction

Now connect the header action button to your autolaunched Flow so it triggers when clicked.

**Where you are:** Still in the Dynamic Component builder, now configuring the interaction

1. **Add the interaction:**
   * In the **Interactions panel**, click **"Add Interaction"**
   * **Interaction Type:** Select `Header Action Click`
   * **Target Name:** Select the "Set as Active" header action button you created in Step 3
2. **Set the action type:**
   * **Type:** Select `Execute Flow`
3. **Configure the Flow connection:** **Flow API Name:**
   * Enter: `Set_Contact_Status_Active`
   * This must match exactly the API name of the autolaunched Flow you created in Step 1
4. **Pass the selected Contact IDs to the Flow:** **Flow Input Variables:**
   * Click **"Add Input Variable"**
   * **Name:** `ContactIds` (must match exactly with your Flow's input variable name)
   * **Value:** Click the **Mapped icon** (🔗)
     * Navigate to your Data Table component
     * Select: `{!DataTableComponentName.SelectedRowsKeyValue}`
   * **Important:** Toggle on **"Allow Multiple values (collection)"**
     * This allows passing multiple selected Contact IDs from the Data Table to the Flow as a collection
     * Without this, only one Contact ID would be passed
5. **Configure what happens after the Flow completes:** **On Finish Actions:**
   * Click **"Add Item"** → **"Refresh All Queries"**
   * This automatically reloads the Data Table to display the updated Status values after the Flow finishes.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FY0fprsA0dCmErJdoLr6d%2F2025-11-13_20-39-13.png?alt=media&#x26;token=83a2a4ea-d2cb-49c7-9ac5-0d3f3dfe04aa" alt="" width="563"><figcaption></figcaption></figure>

***

**What you've configured:** When users click the "Set as Active" button, the Execute Flow interaction captures all selected Contact IDs from the Data Table, passes them as a collection to your Flow, and refreshes the table once the update is complete
{% endstep %}

{% step %}

#### Activate and test

Now that everything is configured, it's time to test your work:

1. **Save your Dynamic Component:**
   * Click **Save** in the Dynamic Component builder to save all your changes
2. **Deploy to a Lightning page:**
   * Navigate to a Lightning page where you want to use this functionality (e.g., a Contact list page or home page)
   * Edit the page and add your Dynamic Component to it
   * **Save** and **Activate** the page
3. **Test the functionality:**
   * Go to the Lightning page where you added your component
   * Select one or more Contact rows by clicking the checkboxes
   * Click the **"Set as Active"** header button
   * Verify that:
     * The selected Contacts' Status updates to "Active"
     * The Data Table refreshes automatically to show the changes
     * You can select and update multiple Contacts at once
       {% endstep %}
       {% endstepper %}

***

{% hint style="warning" %}

## Important Considerations

* **Autolaunched Flows Only:** The "Execute Flow" interaction only works with *autolaunched* Flows, not Screen Flows.
* **Input/Output Variable Names:** The API names of your input and output variables *must* match strictly between the Flow and the "Execute Flow" configuration.
* **Error Handling:** Use the "On Error" action to handle any errors that might occur during flow execution gracefully.
* **Data Types:** Ensure that the data types of your input and output variables match between the Flow and the component.
  {% endhint %}

***

## **In Summary**

The **Execute Flow** interaction lets you trigger autolaunched Flows directly from your Dynamic Components, enabling powerful automation without requiring users to leave the page.

### **Key capabilities**

* **Automate tasks in the background** - Update records, perform calculations, or execute complex business logic when users interact with your component
* **Pass dynamic data to Flows** - Send context-specific information like selected record IDs, user inputs, or field values through input variables
* **Handle results intelligently** - Capture Flow outputs and use them to update your UI, display messages, or trigger follow-up actions
* **Create seamless experiences** - Combine Execute Flow with actions like refreshing data, showing toast notifications, or navigating to different pages to keep users informed

### **Best practices**

* Always use **autolaunched Flows** (not Screen Flows) with this interaction
* Ensure variable names match **exactly** between your Flow and the Execute Flow configuration
* Use **collections** for input variables when working with multiple selected records
* Configure **On Finish** and **On Error** actions to provide clear feedback to users
* Test thoroughly with both single and multiple record selections

The Execute Flow interaction bridges the gap between user interface and automation, allowing you to build sophisticated, user-friendly applications that leverage the full power of Salesforce Flows
