---
schema_version: "1"
id: 07c55c1992ea0a99f7e0a9058d192f82b5eb8be97151099ae6a7351b016e3277
title: Subflow (<sub-flow/>)
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/anypoint-code-builder/acb-component-subflow.md
canonical_url: https://docs.mulesoft.com/anypoint-code-builder/acb-component-subflow
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 109db39f1fbab2b3671fbb8d434195055fa47bf353738bd10e6718e66c5e7ddb
description: MuleSoft Documentation Site
latest: true
---
---
product: Anypoint Code Builder
version: master
---

# Subflow (<sub-flow/>)

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

Group together a sequence of Core components and operations (provided by connectors and modules)
inside a scope that you invoke from a Flow Reference in your Mule application.

The Subflow component works in a similar way to the [Flow](https://docs.mulesoft.com/anypoint-code-builder/acb-component-flow) component but with
the following differences:

- Subflows do not support Mule event sources.

- Subflows do not have a built-in error handling scope.

- During design, subflows work as macros that replace the Flow Reference components that call them.

  When you build the application, Mule replaces all Flow Reference components that call a subflow
  with the contents of the referenced subflow.

- Referencing subflows results in better performance than referencing a flow.

You can create multiple subflows in your Mule application.

For a more in-depth discussion of uses, capabilities, and limits of flows and subflows, see
[Flows and Subflows](https://docs.mulesoft.com/mule-runtime/latest/about-flows).

## Limitations

Because the contents of a subflow replace each Flow Reference component that references that
subflow, several instances of the event processors inside that subflow exist in the application at
runtime. This behavior can cause issues with event processors that depend on unique IDs or instances
to execute.

## Component XML

This component supports the following XML structure:

```xml
<sub-flow name="mySubFlow">

</sub-flow>
```

Subflow (`<sub-flow/>`) attributes are configurable through the UI and XML.

<table><colgroup><col> <col> <col></colgroup><thead><tr><th>Attribute Name</th><th>Attribute XML</th><th>Description</th></tr></thead><tbody><tr><td><p><strong>name1</strong> (default)</p></td><td><p><code>name</code></p></td><td><div><div><p>Editable name for the subflow.</p></div></div></td></tr></tbody></table>

## Find Flows That Reference This Subflow

You can find every flow that references a subflow without searching the project manually. To list
the references, right-click the subflow in the canvas and select **Find References**. You can also
press Shift+Alt+F12 (Windows and macOS).

Anypoint Code Builder lists each flow reference that points to the selected subflow, including
references in other configuration files and in MUnit tests. Select a reference to open that
location.

This helps you trace execution paths and assess the impact of changes to a reusable subflow.

For more information, see
[Find Flows That Reference a Subflow](https://docs.mulesoft.com/anypoint-code-builder/int-configure-components#find-referencing-flows).

## Example: Flow and Subflows

The following example uses a Scheduler as a source to trigger the execution of a flow every 10
seconds and then connects to a subflow (`<sub-flow/>`) through a Flow Ref (`<flow-ref/>`) component.
The subflow then connects to another subflow, also using a Flow Ref component.

```xml
<flow name="flow_component_ex">
  <scheduler doc:name="Scheduler" >
    <scheduling-strategy >
      <fixed-frequency frequency="10" timeUnit="SECONDS"/>
    </scheduling-strategy>
  </scheduler>
  <ee:transform doc:name="Transform Message">
    <ee:message >
      <ee:set-payload ><![CDATA[
 %dw 2.0
 var myXml =  read('<prices>
    <basic>9.99</basic>
    <premium>53</premium>
    <vip>398.99</vip>
  </prices>', 'application/xml')
 output application/xml
 ---
 myXml
]]></ee:set-payload>
    </ee:message>
  </ee:transform>
  <flow-ref name="subflow_ex1"/>
</flow>
<sub-flow name="subflow_ex1">
  <ee:transform doc:name="Transform Message">
    <ee:message>
      <ee:set-payload><![CDATA[%dw 2.0
import * from dw::util::Timer
output application/json
var conversionRate=13
---
priceList: payload.prices mapObject(value, key, index) -> {
  (key) : {
       dollars: value,
       localCurrency: value * conversionRate,
       index_plus_1: index + 1,
       timer : currentMilliseconds()
   }
}]]>
      </ee:set-payload>
   </ee:message>
 </ee:transform>
 <flow-ref name="subflow_ex2"/>
</sub-flow>
<sub-flow name="subflow_ex2">
  <logger level="INFO" doc:name="Logger" message="#[payload]" />
</sub-flow>
```

The example produces the following output:

```json
{
  "priceList": {
    "basic": {
      "dollars": "9.99",
      "localCurrency": 129.87,
      "index_plus_1": 1,
      "timer": 1533024312658
    },
    "premium": {
      "dollars": "53",
      "localCurrency": 689,
      "index_plus_1": 2,
      "timer": 1533024312659
    },
    "vip": {
      "dollars": "398.99",
      "localCurrency": 5186.87,
      "index_plus_1": 3,
      "timer": 1533024312659
    }
  }
}
```

## See Also

- [Flow](https://docs.mulesoft.com/anypoint-code-builder/acb-component-flow)
