# Flow variables with Set and Remove Variable

*MuleSoft Developer Study Guide · Accessing and Modifying Mule Events · Last updated October 28, 2026 · https://www.certifyforce.com/study-guide/mulesoft-developer/accessing-and-modifying-mule-events/flow-variables-with-set-and-remove-variable*

How Mule 4 variables are created (Set Variable, Transform Message, operation targets), read with `vars`, removed with Remove Variable, and scoped to the flow and its Flow Reference calls, including what a variable holding `payload`, `attributes` or `message` returns later and why error handlers can still read it.

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

**Official exam objective:**

> Apply correct processors/DataWeave expressions to access and modify Mule variables, and predict outcomes.

## What the exam expects

- Read a variable with `vars.name` and reject expressions such as `flowVars.name`, `variables.name` or `message.name`.
- Name the ways to create or update a variable (Set Variable, an operation's target, Transform Message) and pick Transform Message when one step must set both the payload and a variable.
- Predict what Remove Variable does to a later read, and what happens when it names a variable that does not exist.
- Predict what a variable that stored `#[payload]`, `#[attributes]` or `#[message]` returns after later components change the message.
- Decide where a variable is visible: the flow, flows joined by Flow Reference and the error handler, but not another Mule application called over HTTP.
- Key terms: **Mule variable** (per-event value stored on the event, outside the message); **`vars`** (predefined DataWeave variable holding all variables on the event); **Set Variable** (Core transformer that creates or updates a variable); **Remove Variable** (Core transformer that deletes a variable from the event).

## Key facts

| Fact | Detail | Source |
|---|---|---|
| Read syntax | `vars.myVar` | [Variables in Mule Apps](https://docs.mulesoft.com/mule-runtime/latest/about-mule-variables) |
| Ways to create or update | Set Variable, operation target, Transform component, Scripting component | [Variables in Mule Apps](https://docs.mulesoft.com/mule-runtime/latest/about-mule-variables) |
| Keyword values | `payload`, `attributes`, `message` allowed; `vars` not allowed | [Variables in Mule Apps](https://docs.mulesoft.com/mule-runtime/latest/about-mule-variables) |
| Variable names | Numbers, characters and underscores only; no hyphens | [Set Variable Transformer](https://docs.mulesoft.com/mule-runtime/latest/variable-transformer-reference) |
| Transform Message variables | `<ee:set-variable>` inside `<ee:variables>`, beside `<ee:set-payload>` | [Transform Component XML Reference](https://docs.mulesoft.com/mule-runtime/latest/transform-dataweave-xml-reference) |
| Removed variable read | Returns `null` | [Remove Variable Transformer](https://docs.mulesoft.com/mule-runtime/latest/remove-variable) |
| Removing a missing variable | Logs `WARN`; no error | [Remove Variable Transformer](https://docs.mulesoft.com/mule-runtime/latest/remove-variable) |
| Scope | The flow plus flows joined by Flow Ref | [Variables in Mule Apps](https://docs.mulesoft.com/mule-runtime/latest/about-mule-variables) |
| Flow Reference reach | Routes the event within the same Mule application | [Flow Reference Component](https://docs.mulesoft.com/mule-runtime/latest/flowref-about) |
| Error handler | A variable set before processing keeps the original payload for the handler | [Set Variable Transformer](https://docs.mulesoft.com/mule-runtime/latest/variable-transformer-reference) |

## Check yourself

- Why would a variable named `claim-id` be rejected by Set Variable?
- When is a variable declared with `var` inside a DataWeave script visible?
- What happens to variable changes made by a referenced flow when the Flow Reference has no target?
- Why can a flow called by Flow Reference read the caller's variables?

## Sources

- [Variables in Mule Apps](https://docs.mulesoft.com/mule-runtime/latest/about-mule-variables)
- [Set Variable Transformer](https://docs.mulesoft.com/mule-runtime/latest/variable-transformer-reference)
- [Remove Variable Transformer](https://docs.mulesoft.com/mule-runtime/latest/remove-variable)
- [Predefined Variables](https://docs.mulesoft.com/dataweave/latest/dataweave-variables-context)
- [Mule Event Structure](https://docs.mulesoft.com/mule-runtime/latest/about-mule-event)
- [Mule Message Structure](https://docs.mulesoft.com/mule-runtime/latest/about-mule-message)
- [Transform Component XML Reference](https://docs.mulesoft.com/mule-runtime/latest/transform-dataweave-xml-reference)
- [Flow Reference Component](https://docs.mulesoft.com/mule-runtime/latest/flowref-about)
- [Core Components](https://docs.mulesoft.com/mule-runtime/latest/about-components)
- [Configure HTTP Listener Source](https://docs.mulesoft.com/http-connector/latest/http-listener-ref)
- [Enrich Data with Target Variables](https://docs.mulesoft.com/mule-runtime/latest/target-variables)

## About the full unit

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