# For Each and Parallel For Each scopes

*MuleSoft Developer Study Guide · Processing Records · Last updated October 28, 2026 · https://www.certifyforce.com/study-guide/mulesoft-developer/processing-records/for-each-and-parallel-for-each-scopes*

Predict the payload, variables and error behaviour after a For Each or Parallel For Each scope, configure `collection` and `batchSize`, and know when a Batch Job is the better tool.

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

**Official exam objective:**

> Apply correct processors/syntax to process individual records in a collection using For Each scopes, and predict outcomes.

## What the exam expects

- Configure a For Each scope's `collection` expression so each element of a JSON or XML array becomes the payload inside the scope.
- Predict the number of iterations and each iteration's payload for a given `batchSize`.
- Predict the payload and the variables after a For Each scope and after a Parallel For Each scope.
- Predict what happens when one element fails: For Each stops, Parallel For Each finishes every route and raises `MULE:COMPOSITE_ROUTING`.
- Choose a Batch Job over Parallel For Each when the input is too large to buffer in memory or must survive a redeployment.

Key terms:
- **Collection**: the expression that returns what the scope splits; the default is `payload`.
- **Batch size**: the size of each sub-collection For Each processes as one Mule message.
- **Root message**: the complete, non-split parent message, stored in a variable.
- **Route**: one parallel branch of Parallel For Each, processing one element.

## Key facts

| Fact | Detail | Source |
|---|---|---|
| For Each output payload | Same as the input payload | [For Each Scope](https://docs.mulesoft.com/mule-runtime/latest/for-each-scope-concept) |
| `collection` default | `payload`; use a DataWeave expression for JSON or XML | [For Each Scope](https://docs.mulesoft.com/mule-runtime/latest/for-each-scope-concept) |
| `batchSize` default | `1`; 200 elements at 50 = 4 batches of 50 | [For Each Scope](https://docs.mulesoft.com/mule-runtime/latest/for-each-scope-concept) |
| For Each variables | Changes persist across iterations and after the scope | [For Each Scope](https://docs.mulesoft.com/mule-runtime/latest/for-each-scope-concept) |
| For Each error | Stops processing the collection, invokes the error handler | [For Each Scope](https://docs.mulesoft.com/mule-runtime/latest/for-each-scope-concept) |
| Parallel For Each output | Collection of route results in pre-split order | [Parallel For Each Scope](https://docs.mulesoft.com/mule-runtime/latest/parallel-foreach-scope) |
| Parallel For Each variables | Same set and values after the scope as before | [Parallel For Each Scope](https://docs.mulesoft.com/mule-runtime/latest/parallel-foreach-scope) |
| Parallel For Each error | All routes finish, then `MULE:COMPOSITE_ROUTING` | [Parallel For Each Scope](https://docs.mulesoft.com/mule-runtime/latest/parallel-foreach-scope) |
| Batch Job reliability | Persistent queues; resumes after redeploy or crash | [Batch Processing](https://docs.mulesoft.com/mule-runtime/latest/batch-processing-concept) |

## Check yourself

- What payload does the processor after a For Each scope receive?
- Why must the Collection field be set when the payload is a JSON object containing an array?
- Why is a counter incremented inside Parallel For Each unchanged after the scope?
- When should a Batch Job replace Parallel For Each?

## Sources

- [For Each Scope](https://docs.mulesoft.com/mule-runtime/latest/for-each-scope-concept)
- [Parallel For Each Scope](https://docs.mulesoft.com/mule-runtime/latest/parallel-foreach-scope)
- [Batch Processing](https://docs.mulesoft.com/mule-runtime/latest/batch-processing-concept)
- [Try Scope](https://docs.mulesoft.com/mule-runtime/latest/try-scope-concept)

## 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
