# Choice router conditions and route order

*MuleSoft Developer Study Guide · Routing Events · Last updated October 28, 2026 · https://www.certifyforce.com/study-guide/mulesoft-developer/routing-events/choice-router-conditions-and-route-order*

Predict which Choice route runs from its DataWeave `when` expressions (first true wins, `otherwise` as the default), avoid String versus Number and Boolean comparison traps, and choose DataWeave `if`/`else` or the First Successful router when Choice is the wrong tool.

- Certification: Salesforce MuleSoft Developer
- Exam section: Routing Events
- Study guide: https://www.certifyforce.com/study-guide/mulesoft-developer

**Official exam objective:**

> Apply correct processors/syntax to route messages using DataWeave conditions within a choice router, and predict outcomes.

## What the exam expects

- Predict which route of a Choice router runs, given the `when` expressions in their declared order and an input event.
- Write the Mule 4 XML for a Choice router: `<choice>`, one or more `<when expression="#[...]">` elements and an optional `<otherwise>` default route.
- Spot DataWeave conditions that fail because of type: Strings from query parameters compared with Numbers, and `==` versus `~=` against Booleans.
- Predict the payload and variables after a route that calls a subflow.
- Choose DataWeave `if`/`else` when routes only differ in a value, and the First Successful router when the next route must run only after a failure.

Key terms:
- **Choice router**: runs exactly one route, chosen by DataWeave expressions.
- **`when` route**: a routing option whose `expression` holds the condition.
- **Default route**: the `<otherwise>` element, labelled Default in Studio, which runs when no expression is `true`.
- **First Successful router**: tries routes in order until one completes without an error.
- **`~=`**: the DataWeave equality operator that coerces one operand to the other's type.

## Key facts

| Fact | Detail | Source |
|---|---|---|
| Routes that run | Only one: the first `when` whose expression is `true` | [Choice Router](https://docs.mulesoft.com/mule-runtime/latest/choice-router-concept) |
| Later expressions | Not checked once one is `true` | [Choice Router](https://docs.mulesoft.com/mule-runtime/latest/choice-router-concept) |
| No expression true | The default (`<otherwise>`) route executes | [Choice Router](https://docs.mulesoft.com/mule-runtime/latest/choice-router-concept) |
| `<otherwise>` | Optional child of `<choice>`; Studio labels it Default | [Choice Router](https://docs.mulesoft.com/mule-runtime/latest/choice-router-concept) |
| Processors per route | Any number in each `when` and `otherwise` | [Choice Router](https://docs.mulesoft.com/mule-runtime/latest/choice-router-concept) |
| Condition language | DataWeave, in the `expression` attribute | [Choice Router](https://docs.mulesoft.com/mule-runtime/latest/choice-router-concept) |
| Mixed-type relational operands | Right operand coerced to the left operand's type | [DataWeave Operators](https://docs.mulesoft.com/dataweave/latest/dw-operators) |
| `"true" == true` vs `"true" ~= true` | `false` vs `true` | [DataWeave Operators](https://docs.mulesoft.com/dataweave/latest/dw-operators) |
| DataWeave `if` | Every `if` must have a matching `else` | [Flow Control and Scope Operations in DataWeave](https://docs.mulesoft.com/dataweave/latest/dataweave-flow-control) |
| First Successful | Next route runs only after an error; error if none succeed | [First Successful Router](https://docs.mulesoft.com/mule-runtime/latest/first-successful) |

## Check yourself

- What does `('1' ~= 1)` return, and why?
- Why does a new Choice router in Studio already show two routes?
- When does the `else if` branch of a DataWeave `if` supply the value?

## Sources

- [Choice Router](https://docs.mulesoft.com/mule-runtime/latest/choice-router-concept)
- [DataWeave Operators](https://docs.mulesoft.com/dataweave/latest/dw-operators)
- [Flow Control and Scope Operations in DataWeave](https://docs.mulesoft.com/dataweave/latest/dataweave-flow-control)
- [First Successful Router](https://docs.mulesoft.com/mule-runtime/latest/first-successful)
- [Scatter-Gather Router](https://docs.mulesoft.com/mule-runtime/latest/scatter-gather-concept)

## About the full unit

The "Core concepts", "Exam traps" and "Worked scenario" sections of this unit, its 9 linked practice questions, and unlimited timed mock exams are included with the MuleSoft Developer pack (USD $19): https://www.certifyforce.com/practice-exams
