---
schema_version: "1"
id: ff65cd1fdeb9baaa61dfe6d15c3e4adb658187f243926b83efade6bce34ba598
title: Using Actions in a Flow
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/composer/ms_composer_using_actions_in_a_flow.md
canonical_url: https://docs.mulesoft.com/composer/ms_composer_using_actions_in_a_flow
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 37ec5fd50926982984926c4bdb1d0c94995bbea1ba2025d527bd87d1a87c6694
description: MuleSoft Documentation Site
latest: true
---
---
product: Composer
---

# Using Actions in a Flow

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

An _action_ step in a Composer flow performs a task in a system. An action might extract data from a
system, manipulate data, or send a notification in a system.

## Create an Action

To create an action:

1.  After the trigger in your flow, click the large plus sign to open the **Add Action** dialog.

2.  Click or create a connection for the action.

    For example, if your trigger is "new records created in Salesforce," and you want your action to
    be "copy new record to a Google Sheet," then you would choose or create a Google Sheet
    connection.

3.  Select an action, and any other values displayed. What you have to specify for an action depends
    on system type you are connected to for the action.

4.  If you want to edit a field, and that field is enabled for a
    [custom expression](https://docs.mulesoft.com/composer/ms_composer_custom_expression_editor#add-custom-expression-to-an-action),
    click the pencil icon.  
    Note that you can only enter text or select a single data pill for a field. If you want to enter
    a complex expression (including functions, math operators, concatenation of text, and special
    tokens), you must use the **Custom Expression Editor**.

5.  Click **Save**.

When there are null values in custom expressions and are:

- Fields without attributes, the null value is ignored. If the value in a required field, an error
  message occurs. If the value is in an optional field, the value is ignored and not sent to the
  connector.

- Fields with attributes, the value is ignored and not sent to the connector.

## Define a Variable

You can define variables in your Composer flow. Defining a variable enables you to complete certain
use cases, such as aggregating calculations and storing values. You define variables locally within
a flow and use them anywhere within that flow.

### Access the Variable Step

To access the **Variable** step:

1.  [Create a new flow](https://docs.mulesoft.com/composer/ms_composer_using_a_flow_and_creating_trigger#create-a-flow) or open an
    existing flow.

2.  In the **<Flow Name>** page, click **Edit**.

3.  Locate the position in your flow where you want to access the **Variable** step and click the
    plus button.

4.  In the **Next Step** window, click **Variable**.  
    The **Variable** step appears.

### Create a Variable by Using the Visual Editor

To create one or more new variables using the **Visual Editor** window:

1.  [Access the **Variable** step.](#access-the-variable-step)

2.  Select **Action** > **Create Variable**.

3.  From the **Variable** section, click **Add Variable**.

4.  In the **Label** field, enter a unique name for the variable.

    The name entered is unique only to this step. You can duplicate values in the **Label** field
    across different Variable steps.

5.  In the **Data Type** dropdown, select the data type to use for the variable. The following
    [data types](https://docs.mulesoft.com/composer/ms_composer_custom_expression_editor#data-types) are supported: `String`, `Number`,
    `Boolean`, `Date`, `DateTime` and `List`. If you select **List**, in the **List Item Type**
    field, select:

    - **String**, **Number**, or **Boolean** to return a list that contains primitive data types

    - **Object** to return a list of objects, for example, the output of the **Get Records** action

    Repeat the steps 4 and 5 until you added all the required fields for the Variable step.

6.  To add additional variables in the Visual Editor, click **Add Variable**. You can create
    multiple variables in each Variable step.

7.  Click **Apply**.

8.  To modify the new variables, click **Manage Variables** to open the Visual Editor or **Edit
    Schema** to open the JSON Schema.

### Create a Variable by Using the JSON Schema

To create one or more new variables using the **JSON Schema** window:

1.  [Access the **Variable** step.](#access-the-variable-step)

2.  Select **Action** > **Create Variable**.

3.  In the **Variable** section, click **Create Schema**.

4.  In the **JSON Schema** window, enter the properties for the variable to create.

    Note that each variable is defined within a `Properties` object with a `Variable Unique ID`. The
    `Variable Unique ID` enables the variable to be tracked within your flow. The
    `Variable Unique ID` can contain only alphanumeric characters, hyphens, and underscores. When
    using the Visual Editor, this ID is automatically generated for you. Each variable must specify
    the title and data type. To set the properties for the variable definition, complete the
    following:

    - `Variable Label (Title)`: Display label for the variable. (Required)

    - `Type`: Data type of the variable. The following
      [data types](https://docs.mulesoft.com/composer/ms_composer_custom_expression_editor#data-types) are supported: `String`,
      `Number`, `Boolean` and `Array`.

      To define a `Date` or `DateTime` variable, set the data type to `String` and define the
      `Format` property. (Required)

    - `Format`: Qualifier for `String` properties that can specify additional data types not
      natively supported in JSON. For variables, set this value when defining `Date` or `DateTime`
      variables as `date` or `date-time` respectively. (Optional)

    - `Items`: Item type for `List` variables. `Items` is an object and accepts the following child
      properties: (Required only when defining List variables)

      - `Type`: Data type of the variable. The following data types are supported for List items:
        `String`, `Number`, `Boolean`, and `Object`. If defining an `Object`, you must also define
        the properties of that `Object`. (Required)

      - `Properties`: Child properties of an object. `Properties` is required if the
        `List Item Type` is set to `Object`. In the `Properties` object, each property key is the
        name of the property in the `Object List Item` and is set to an object that defines its data
        type. For more information in defining the data type of object child properties, refer to
        `Type` (step 4b) and `Format` (step 4c). (Optional)

      The properties and values appear in the **JSON Schema** window.

    Example: Properties and values in the **JSON Schema** window

    ```JSON
    {
    "properties": {
    "var-01": {
    "type": "string",
    "title": "My String"
    },
    "var-02": {
    "type": "number",
    "title": "My Number"
    },
    "var-03": {
    "type": "boolean",
    "title": "My Boolean"
    },
    "var-04": {
    "type": "string",
    "title": "My Date",
    "format": "date"
    },
    "var-05": {
    "type": "string",
    "title": "My Datetime",
    "format": "date-time"
    }
    }
    }
    ```

5.  To add variables in the JSON Schema, enter them in the window.

6.  Click **Apply**.

7.  To modify the new variables, click **Manage Variables** to open the Visual Editor or **Edit
    Schema** to open the JSON Schema.

### Initialize a Variable

After creating a variable, you can initialize it:

1.  Create a new variable by using either the
    [Visual Editor](#create-a-variable-using-the-visual-editor) or the
    [JSON Schema](#create-a-variable-using-the-json-schema).

2.  Complete the initial value for each variable. If variable’s data type is:

    - `String`, `Number`, `Boolean`, `Date`, or `DateTime`, the default value is defined under each
      variable. If the field is empty, the value is set to the default value for that data type. You
      can enter a value manually, select any existing data pill (including variables) from your
      flow, select a [Picklist Mapping](#create-a-picklist-mapping) (for `String` variables) or you
      can select the
      [**Custom Expression Editor**](https://docs.mulesoft.com/composer/ms_composer_custom_expression_editor#add-custom-expression-to-an-action)
      to create a custom expression.

    - `List`, the default value is defined under each variable. If the field is empty, the value is
      set to the default value for that data type. You can enter a value manually. For primitive
      list types (`String`, `Number`, `Boolean`, `Date`, or `DateTime`), you can create a list
      statically using the
      [**Custom Expression Editor**](https://docs.mulesoft.com/composer/ms_composer_custom_expression_editor#add-custom-expression-to-an-action)
      or [map in a list data pill](#create-a-picklist-mapping). For List<Objects>, select either:

      - **Dynamic List** to create multiple items in the list. Use a list pill to reference the
        number of items created. Then, map the fields of the elements of the list.

      - **Static List**, and then initialize the list with as many items as you need. If you do not
        add any items, the list is empty by default.

    The variable is initialized.

### Update a Variable

#### Before You Begin

If you are updating a variable with a value created from another variable, do not update them in the
same step. Variables are not necessarily updated in the same order in which they are listed. To
avoid unexpected behavior, update each variable in separate steps.

To update one or more variables:

1.  [Access the **Variable** step.](#access-the-variable-step)

2.  Select **Action** > **Update Variable**.

3.  In the **Variable** section, click **Select Variables**.  
    The **Select Variables** window appears, displaying a list of all variables included in your
    flow before this step.

4.  Select the checkbox next to one or more variables or click **Select all <Number> variables** to
    select all variables in the list.

5.  Click **Apply**.  
    The **Update Variable** step appears.

6.  Update the value for each variable. If the data type for the variable your selected is a:

    - `String`, `Number`, `Boolean`, `Date`, or `DateTime`, you can enter a value manually, select
      any existing data pill (including variables) from your flow, select a
      [Picklist Mapping](#create-a-picklist-mapping) (for `String` variables) or you can select the
      [**Custom Expression Editor**](https://docs.mulesoft.com/composer/ms_composer_custom_expression_editor#add-custom-expression-to-an-action)
      to create a custom expression.

    - `List`, you can add items to the start or the end of the list or replace the existing list
      with a new list. For primitive list types (`String`, `Number`, `Boolean`, `Date`, or
      `DateTime`), you can create a list statically using the
      [**Custom Expression Editor**](https://docs.mulesoft.com/composer/ms_composer_custom_expression_editor#add-custom-expression-to-an-action)
      or [map in a list data pill](#create-a-picklist-mapping). For List<Objects>, select either:

      - **Dynamic List** to create multiple items in the list. Use a list pill to reference the
        number of items created. Then, map the fields of the elements of the list.

      - **Static List**, and then initialize the list with as many items as you need. If you do not
        add any items, the list is empty by default.

## Create a Picklist Mapping

Using Picklist Mapping, you can map data from one application to the corresponding data needed by
another application and then reuse those mappings in different flows in your organization. This
enables you to connect two applications that have different values for similar fields and to align
the values in those fields across applications. You can then determine how the possible values of an
output field (data pill) map to the possible values of an input field.

For example, you can map a data pill from the **Country** field in a Salesforce record and provide
the same values in the **Country** field of the NetSuite record.

<table><colgroup><col> <col></colgroup><thead><tr><th>Country (Salesforce)</th><th>Country (NetSuite)</th></tr></thead><tbody><tr><td><p>US</p></td><td><p>_unitedStates</p></td></tr><tr><td><p>CA</p></td><td><p>_canada</p></td></tr><tr><td><p>DE</p></td><td><p>_germany</p></td></tr><tr><td><p>AR</p></td><td><p>_argentina</p></td></tr></tbody></table>

In this example, the **Status** field in a case in Salesforce is mapped to the **Status** field in a
ticket in Zendesk to create continuity in field values across systems.

<table><colgroup><col> <col></colgroup><thead><tr><th>Status (Salesforce)</th><th>Status (Zendesk)</th></tr></thead><tbody><tr><td><p>New</p></td><td><p>New</p></td></tr><tr><td><p>Working</p></td><td><p>Open</p></td></tr><tr><td><p>Waiting on Customer</p></td><td><p>On-Hold</p></td></tr><tr><td><p>Escalated</p></td><td><p>Open</p></td></tr><tr><td><p>Closed</p></td><td><p>Closed</p></td></tr></tbody></table>

When mapping source data fields:

- The source field must be a data pill with a fixed list of values.

- The target field must be an enumerated
  [data type](https://docs.mulesoft.com/composer/ms_composer_custom_expression_editor#data-types) field or any string field.

- If any other unmapped value from the source system is found, the default mapping specifies the
  value in the target system. If you do not specify a default value, the original value from the
  source field is passed to the target field.

- The mapping is stored at the organization level and can be reused across flows. No additional
  steps are needed to reuse mappings across different flows.

- The mapping must have a unique name.

- Mappings are available to everyone in your organization.

To map source data fields to target fields:

1.  From the **Composer Flows** tab, open a flow and click **Edit**.

2.  In an action card, in a field that supports **Pick from List** or any string field, select
    **Picklist Mapping** from the menu.  
    The **Picklist Mapping** window appears.

3.  In the **Picklist Source** section, in the **Source** field, select the value from the list that
    you want to map to the value in the **Target** field, and then click **Next**.

4.  In the **Global Picklist Selection** section, create a new picklist or choose an existing
    picklist.

### Create A New Picklist

To create a new picklist:

1.  Click **Create new picklist**.

2.  In the **Global picklist name** field, enter a unique name for the picklist.

3.  Optionally, in the **Description** field, enter a description for the picklist. The following
    description is populated automatically based on your source and target systems:  
    `This maps [Source Field Name] from [Source Connection Name] to [Target Field Name] from [Target Connection Name]`

4.  In the table, select the source fields and their target mappings.

5.  To add additional field mappings, click **Add Row** and if the additional field mapping is a:

    1.  **Pick from List** field, enter the source field values manually (with a row representing
        each value) and select the target mappings from the dropdown.

    2.  String field, manually define the value in the target field.

6.  Once you have added all applicable field mappings, click **Create Picklist**.

7.  Click **Apply**.  
    The **<Picklist Name>** section appears, displaying a table of values and their mappings.

### Choose An Existing Picklist

To choose an existing picklist:

1.  Select a picklist from the list. Note that all edits made to an existing picklist will impact
    all flows in which that picklist is currently used.

2.  Optionally, in the **<Picklist Name>** section, to edit the values, click the pencil. Once you
    have edited the values, click **Save Picklist** and then click **Apply**.

3.  Optionally, in the **<Picklist Name>** section, to delete the picklist, click the trashcan. Note
    that deleting a global picklist will affect all flows currently using that picklist.

4.  Click **Apply**.  
    The action card appears.

## Create a Flow Control

If you need to perform some logic before an action, select a flow control first:

1.  After the trigger in your flow, click the large plus sign to open the **Add Action** dialog.

2.  Click either **If/Else Block** or **For Each**. An If/Else block is good when you need to do
    different actions depending on one or more conditions. A For Each loop is good for processing a
    set of records.

3.  Complete the flow control, which usually includes adding an action.

4.  Click **Save**.

### Add An If/Else Block

You can create an If/Else block to set conditions and execute actions only when specific criteria
are met. This enables you to create flows that cover more than one linear branch, without the need
to create separate flows.

Branches are logic-based steps that run vertically in a flow. You can add multiple steps inside each
branch. Each branch is then executed in sequential order.

When adding decision steps, the values in the **Field** list are populated based on values selected
when you specify the previous steps of your flow. After the **Field** value is selected, all
compatible value options appear in the [**Operator**](#supported-operators) list. If the selected
**Operator** requires a second data pill to complete the condition, then the **Value** field is
enabled and the list is populated based on the values you selected when defining the trigger. In the
**Value** field, you can either enter a value manually or you can set it using the existing data
from your flow.

For the purposes of comparing flows, if you initiate a date comparison when building a flow and
there is no value in one of the date fields, the missing value is updated to `0001-01-01` by
default.

The following operators are supported when building conditions in an If/Else block:

<table id="supported-operators"><colgroup><col> <col> <col> <col></colgroup><thead><tr><th>Function</th><th>Supported Data Type</th><th>Value Required?</th><th>Notes</th></tr></thead><tbody><tr><td><p>Equals/Does not equal</p></td><td><p>All</p></td><td><p>Yes</p></td><td><p>The value in this field is case-sensitive for strings.</p></td></tr><tr><td><p>Contains/Does not contain</p></td><td><p>Array, String</p></td><td><p>Yes</p></td><td><p>None</p></td></tr><tr><td><p>Greater than/Less than</p></td><td><p>Date, Number</p></td><td><p>Yes</p></td><td><p>In the <strong>Date</strong> field, the <strong>Greater than</strong> value is equal to a later date and the <strong>Less than</strong> value is equal to an earlier date.</p></td></tr><tr><td><p>Greater than or equal/Less than or equal</p></td><td><p>Date, Number</p></td><td><p>Yes</p></td><td><p>In the <strong>Date</strong> field, the <strong>Greater than or equal</strong> value is equal to a later date or the current date and the <strong>Less than or equal</strong> value is equal to an earlier date or the current date.</p></td></tr><tr><td><p>Is empty/Is not empty</p></td><td><p>Array, String, Object</p></td><td><p>No</p></td><td><p>None</p></td></tr><tr><td><p>Starts with/Ends with</p></td><td><p>String</p></td><td><p>Yes</p></td><td><p>A string value for this field is required.</p></td></tr><tr><td><p>Is true/Is false</p></td><td><p>Boolean</p></td><td><p>No</p></td><td><p>None</p></td></tr><tr><td><p>Is present/Is not present</p></td><td><p>All</p></td><td><p>No</p></td><td><p>If the value in this field is null or if there is no value selected, then the value in this field is set to <strong>Not present</strong> by default.</p></td></tr></tbody></table>

To create an If/Else block:

1.  Click the plus sign after the trigger or the last action in your flow.

2.  Click **Add Action**.

3.  Click **If/Else Block** to define the first branch.

4.  Enter the requested criteria. You can specify that `all conditions should be met (AND)`,
    `any condition can be met (OR)`, or [customize](#use-custom-logic) the order and grouping of
    your conditions.

5.  Click **+** to add an action to that branch. Every branch must have an action, also called a
    _step_.

6.  If you want to add another branch, click **Add If** and repeat the previous steps for every
    If/Else branch you create.

7.  If you want to set criteria for how the flow executes if none of the criteria for the existing
    branches are met, click **Add Else** and repeat the previous steps for the final branch.

8.  If you want to add additional conditions to your If/Else block, click **Add condition**.

9.  After you add all the branches, click **Save**.

## Use Custom Logic

Custom logic uses the row number for each condition in the If statement block of an If/Else
statement and `OR`, `AND`, and `NOT` to create complex expressions. When you select the custom logic
option, each condition is assigned a number and you can then use that number to customize the order
of operations for the conditions.

When using custom logic, all conditions defined must be referenced in the expression for the
expression to be validated. For example, if there are three defined conditions and you enter “1 and
(2 or 1)”, the expression is invalid because “3” is not referenced.

Using custom logic, you can have up to 20 conditions and a condition can be referenced more than
once.

## Create A For Each Loop

To create a For Each Loop:

1.  Click the plus sign after the trigger or the last action in your flow.

2.  Click **Add Action**.

3.  Click **For Each**.

4.  Choose a data pill from the **Input list**. You must have a trigger or action that returns a set
    of records or there won’t be anything to choose here.

5.  Click the plus sign to add an action.

6.  After you complete the action, click **Save**.

You can add logic and actions in different patterns, depending on what your flow needs to do.

## Configure Error Handling

When executing a flow, you can watch for connection or logic errors in specific steps of your flow
and then specify logic to handle the errors. You can also configure steps to complete additional
actions or to send notifications if an error occurs.

### Access Error Handling

To access the error handler:

[Create a new flow](https://docs.mulesoft.com/composer/ms_composer_using_a_flow_and_creating_trigger#create-a-flow) or open an existing
flow. . If you create a new flow: .. Select the connector or system to start your flow. .. Select
and configure a trigger. .. Select and configure an action. .. Directly before the step to which you
want to add an error handler, click the plus button. .. In the **What Should Start This Flow?**
window, click **Error Handler**. . If you add a step to an existing flow: .. Open your flow. ..
Directly before the step to which you want to add an error handler, click the plus button. .. In the
**Next Step** window, click **Error Handler**.

### Watch a Step

You can watch specific steps for connection or logic errors. If an error occurs, the flow stops
normal processing and begins processing the steps in the error handler. You can add one or more
steps to watch in this section.

To watch a step:

1.  [Access the error handler in your flow](#access-error-handling).

2.  In the **Error Handler** card, in the **Watch** section, click the plus sign and select the
    action to watch or drag the step to watch into the **Watch** section.  
    The selected action appears in the **Watch** section. If an error occurs, the flow moves to the
    actions selected in the **On Error** section.

3.  To add additional actions to watch, repeat the previous step.

### Configure Composer to Handle Errors

You can configure Composer to handle errors encountered in the **Watch** section. If an error occurs
in a watched action, the **On Error** section begins processing the flow based on your
configuration. You can add one or more steps to run in the **On Error** section.

#### Error Handling Behavior

- By default, the **On Error** section allows for one condition to be met; however, you can add as
  many conditions as you want in this section.

- When adding a new condition, the **On Error** condition field value is set to `None` by default.
  Leaving this value set to `None` returns any errors that may occur in the **Watch** section and
  processes all steps inside this **On Error** section.

- When a condition is met in the **On Error** section, the error handler processes the conditions in
  sequential order and stops once the first condition is met. After the first condition is met, any
  subsequent steps are skipped. If you want the process to continue, you can add an additional **On
  Error** section branch inside your existing **On Error** section.

- When [testing your flow](https://docs.mulesoft.com/composer/ms_composer_test_flow), any errors caught by the error handler appear in
  the right pane of the action card. Successful steps are marked with a green check and failed steps
  are marked with a red X.

- When an error occurs in a watched action, the error information is saved as a data pill that can
  then be used for subsequent notification or record-updating actions. For example, if an error
  occurs, you can specify an action to send an email to your team containing the error information
  from the data pill.

- When configuring error handling, you can establish different sequences to meet your requirements.
  You can:

  - Add all steps in one error handler.  
    If you have the same **On Error** process for any errors or if you can configure multiple **On
    Error** processes with error conditions to handle specific types of errors, then add all steps
    in one error handler. As a result, if any error occurs in the step inside the **Watch** section,
    the remaining steps in the same **Watch** section stop.

  - Add more than one error handler in a flow.  
    You can group steps into seperate error handlers or each step can have its own error handler.
    This provides the flexibility to configure different steps when errors occur.

  - Place an error handler inside a For Each loop.  
    If an error occurs inside a For Each loop, adding an error handler in the for each loop allows
    the loop to continue past an error. To set an error handler to continue after an error occurs,
    in the **After running** drop down, select **Continue**. To provide further clarity on the
    error, add a step to update the failed record for troubleshooting.

#### Add Steps to the On Error Section

To add steps to the **On Error** section of your flow:

1.  [Select a step to watch](#watch-a-step).

2.  In the **Error Handler** card, in the **On Error** section:

    1.  In the **Conditions to run this branch** dropdown, select one of the following conditions
        and then enter the requested criteria:

        - `AND`: Meets all conditions.

        - `OR`: Meets any conditions.

        - `None`: Returns all errors without meeting any conditions.

        - `Custom Logic`: Specify [custom logic](#use-custom-logic) to meet conditions.

    2.  In the **After Running** dropdown, select:

        - **Stop**: After processing all steps in the **On Error** section, Composer flags errors
          and stops the flow. On the **Run History** page, the _Status_ field of the flow shows
          `FAILED`.

        - **Continue**: After processing all steps in the **On Error** section, Composer dismisses
          errors and the flow continues. If no other errors occur, on the **Run History** page, the
          _Status_ field of the flow shows `SUCCESS`.

3.  If you want to add additional conditions to this **On Error** section, click **Add Condition**.

4.  If you want to look for a specific error condition and specify how it is handled within your
    existing **On Error** section, click **Add On Error** to add a new branch with steps.  
    When adding a branch to the **On Error** section, in the **After Running** section, select:

    - **Continue**: Processes **On Error** steps and then continues to the next step within the
      parent step.

    - **Propagate**: Processes **On Error** steps and then pushes the error to the parent error
      handler section. The child step then stops processing and the error handler process returns to
      the parent step.

5.  Optionally, in the **On Error** section, click the plus button to add steps to handle an error:

    1.  In the **Next Step** window, select **System Action**.

    2.  Select an action to complete when an error occurs. For example, add an action to send a
        notification email with the **Record ID** and error information to your team or update the
        source record with error information.

    3.  Configure the action.

6.  Save the flow.

7.  [Test the flow](https://docs.mulesoft.com/composer/ms_composer_test_flow).

8.  [Activate the flow](https://docs.mulesoft.com/composer/ms_composer_activation).

## See Also

- [Mulesoft Composer: Overview](https://docs.mulesoft.com/composer/ms_composer_overview)

- [MuleSoft Composer: Getting Started](https://docs.mulesoft.com/composer/ms_composer_prerequisites)

- [Composer Connector Reference](https://docs.mulesoft.com/composer/ms_composer_reference)

- [Knowledge Articles](https://help.salesforce.com/s/)
