Flow Governor Limits Deep Dive
When to use this skill
Activate when:
- A flow throws
System.LimitException: Too many SOQL queries: 101 or similar.
- You're architecting a flow that will run in a high-volume context (data loader imports, bulk API writes, batch recalcs).
- You need to estimate the limit footprint of adding a flow to an already-busy object trigger stack.
- You're tuning a flow that runs close to the limit ceiling in production.
- You're investigating CPU timeouts on record-triggered flows.
Do NOT use this skill for:
- General Flow bulkification patterns (use
skills/flow/flow-bulkification).
- Apex-only limit math (use
skills/apex/apex-governor-limits if it exists).
- Schema-design decisions driven by record volume (use
skills/architect/large-data-volume-design).
Core concept — limits are per-transaction, not per-flow
The platform enforces governor limits per transaction, not per flow. Two Before-Save flows on the same object share the transaction's SOQL budget. A flow running inside a triggered Apex context inherits the trigger's current consumption.
Critical limits for flows
| Limit |
Synchronous |
Async |
Shared across transaction |
| SOQL queries |
100 |
200 |
Yes |
| SOQL rows |
50,000 |
50,000 |
Yes |
| DML statements |
150 |
150 |
Yes |
| DML rows |
10,000 |
10,000 |
Yes |
| CPU time |
10,000 ms |
60,000 ms |
Yes |
| Heap size |
6 MB |
12 MB |
Yes |
| Callouts |
100 |
100 |
Yes |
Per-element cost approximation
| Flow element |
SOQL |
DML |
Notes |
| Get Records |
1 per element |
0 |
Rows count against 50,000 rows |
| Create Records |
0 |
1 per element |
Rows count against 10,000 |
| Update Records |
0 |
1 per element |
Rows count against 10,000 |
| Delete Records |
0 |
1 per element |
Rows count against 10,000 |
| Loop |
0 |
0 |
Depends on what's inside |
| Assignment |
0 |
0 |
Free |
| Decision |
0 |
0 |
Free |
| Subflow |
Inherited |
Inherited |
Counts against parent transaction |
| Action (invocable Apex) |
Varies |
Varies |
Apex action's own SOQL + DML add up |
The key trap: a Loop with a Get Records inside = 1 SOQL per loop iteration. 200 iterations = 200 SOQL = immediate limit breach.
Recommended Workflow
- Enumerate every DML-class element in the flow (Get, Create, Update, Delete, subflow, action).
- Map which elements are inside loops. Loop + DML/SOQL inside is the #1 limit-breach pattern. Hoist outside the loop via collection-based DML.
- Account for shared limits. If the flow runs on Account save, it shares the 100-SOQL budget with all other Account triggers, VRs, Before-Save flows, After-Save flows, and sharing recalculation.
- Run a budget check:
(max_batch_size × per_record_cost) ≤ 0.7 × limit — leave 30% headroom for other automations sharing the transaction.
- If budget is tight, tune: hoist SOQL/DML out of loops, consolidate Get Records with OR-filters, cache field values, split work across transactions (Scheduled Paths, Platform Events).
- Pre-deployment benchmark. In sandbox, exercise the flow with 200-record batches. Measure SOQL, DML, CPU via
Limits.getQueries() wrapper in an Apex test.
Key patterns
Pattern 1 — Budget a record-triggered flow
Context: flow fires on Account update. Expected batch size: 200 records.
Elements:
- Get Records: related Contacts (1 SOQL, returns avg 5 Contacts per Account = 1000 rows).
- Loop over Contacts with Update Records inside. ← ALARM.
Un-tuned cost per batch:
- SOQL: 1 (Get Records outside loop)
- Contact Update: 1000 DML statements (1 per contact inside loop)
DML-statement limit: 150. Breach at the 150th Contact.
Tuned:
- Outside the loop, collect Contact updates into a collection variable.
- Single Update Records (collection) = 1 DML statement, 1000 DML rows.
Tuned cost: 1 SOQL + 1 DML, 1000 rows. Well under limits.
Pattern 2 — Shared-transaction forecasting
Account trigger stack:
- Before-Save Validation (3 Get Records = 3 SOQL)
- Record-Triggered After-Save Flow A (2 Get Records + 1 Update = 2 SOQL + 1 DML)
- Record-Triggered After-Save Flow B (NEW — 4 Get Records + 1 Create = 4 SOQL + 1 DML)
- Existing Apex trigger (avg 15 SOQL + 3 DML per 200 records)
Total per 200-record batch: 24 SOQL + 5 DML (200 rows).
Available: 100 SOQL, 150 DML, 10,000 DML rows.
Headroom: 76 SOQL (OK).
Adding Flow B costs 4 SOQL + 1 DML from the shared pool. Fine here; if a fourth flow were to be added adding 10 more SOQL, the margin would shrink.
Pattern 3 — Async offload
Same context but Flow B needs to do heavy enrichment (15 SOQL per record):
- Inline: 15 × 200 = 3000 SOQL. Breach.
- Async: mark Flow B's entry as "Run Asynchronously" (Scheduled Path +0 minutes). Fresh transaction per batch of 200 records; fresh 100-SOQL budget.
Trade-off: ~1-5 minute delivery delay, new-transaction idempotency requirement.
Pattern 4 — CPU time tuning
Large loops with Assignments and Decisions consume CPU. Pattern that works in a 10-record test breaches at 200 records:
- Pre-compute lookups into a Map outside the loop (O(1) access inside).
- Avoid nested Loops; if you need Map-of-List shape, pre-compute outside.
- Move complex Formula evaluations out of inner Decisions.
CPU time is the hardest limit to diagnose — symptoms are timeouts, not explicit limit errors.
Pattern 5 — Heap size management
Loop that accumulates all results into a big collection:
- 50,000 sObjects × avg 1 KB each = 50 MB. Heap limit breached at ~6 MB (async: 12 MB).
- Tuning: process in chunks via Scheduled Paths, or use a pass-through filter (transform + DML per chunk, don't accumulate).
Bulk safety
This skill IS the bulk-safety math skill. Rules:
- Never DML inside a Loop.
- Never SOQL inside a Loop.
- Never accumulate unbounded results into a collection.
- Budget for shared transaction — don't assume the flow owns the whole 100 SOQL.
Error handling
Limit exceptions terminate the transaction. Fault paths can't catch System.LimitException — the flow has already exceeded. The only recovery is:
- Reduce element consumption (bulkification).
- Split across transactions (async).
- Reduce batch size upstream (if caller is controllable).
Well-Architected mapping
- Performance — budgeting limits is performance engineering. A flow with 70% limit headroom survives load spikes; a flow at 95% breaks under the first busy day.
- Reliability — shared-transaction math is what predicts cascading failures. Adding "one more flow" to a busy stack without budget analysis is the classic way orgs become fragile.
Gotchas
See references/gotchas.md.
Testing
@IsTest
static void testFlowStaysUnderLimits() {
// Prepare 200-record bulk scenario.
List<Account> accounts = new List<Account>();
for (Integer i = 0; i < 200; i++) {
accounts.add(new Account(Name = 'Test ' + i));
}
Test.startTest();
insert accounts;
Test.stopTest();
// Assert total transaction stayed under 0.7 × limits.
System.assertTrue(Limits.getQueries() < 70, 'SOQL budget exceeded');
System.assertTrue(Limits.getDMLStatements() < 105, 'DML budget exceeded');
}
Official Sources Used
1---2name: flow-governor-limits-deep-dive3description: "Compute and budget governor-limit consumption per Flow type with worked math: SOQL, DML rows, CPU time, heap. Includes per-entry-point budget tables, cross-automation shared-limit math, and tuning strategies when a flow hits a ceiling. NOT for general bulkification (use flow-bulkification). NOT for Apex limits (use apex-governor-limits)."4category: flow5salesforce-version: "Spring '25+"6well-architected-pillars:7 - Performance8 - Reliability9tags:10 - flow11 - governor-limits12 - performance13 - soql14 - dml15 - cpu16 - heap17triggers:18 - "flow governor limits"19 - "flow soql 101 error"20 - "flow cpu time limit"21 - "flow dml rows exceeded"22 - "flow heap size exceeded"23 - "shared limits trigger flow"24inputs:25 - Flow type + entry context26 - Expected records per batch / per transaction27 - Concurrent automations on the same object28 - Existing Apex trigger limit consumption29outputs:30 - Per-element limit budget31 - Shared-transaction budget forecast32 - Tuning recommendations (bulkify, split, async-ify)33 - Pre-deployment benchmark plan34dependencies: []35version: 1.0.036author: Pranav Nagrecha37updated: 2026-04-1738metadata:39 source: https://skillmd.com/skills/banibratachatterjee/flow-governor-limits-deep-dive40---4142# Flow Governor Limits Deep Dive4344## When to use this skill4546Activate when:4748- A flow throws `System.LimitException: Too many SOQL queries: 101` or similar.49- You're architecting a flow that will run in a high-volume context (data loader imports, bulk API writes, batch recalcs).50- You need to estimate the limit footprint of adding a flow to an already-busy object trigger stack.51- You're tuning a flow that runs close to the limit ceiling in production.52- You're investigating CPU timeouts on record-triggered flows.5354Do NOT use this skill for:55- General Flow bulkification patterns (use `skills/flow/flow-bulkification`).56- Apex-only limit math (use `skills/apex/apex-governor-limits` if it exists).57- Schema-design decisions driven by record volume (use `skills/architect/large-data-volume-design`).5859## Core concept — limits are per-transaction, not per-flow6061The platform enforces governor limits **per transaction**, not per flow. Two Before-Save flows on the same object share the transaction's SOQL budget. A flow running inside a triggered Apex context inherits the trigger's current consumption.6263### Critical limits for flows6465| Limit | Synchronous | Async | Shared across transaction |66|---|---|---|---|67| SOQL queries | 100 | 200 | Yes |68| SOQL rows | 50,000 | 50,000 | Yes |69| DML statements | 150 | 150 | Yes |70| DML rows | 10,000 | 10,000 | Yes |71| CPU time | 10,000 ms | 60,000 ms | Yes |72| Heap size | 6 MB | 12 MB | Yes |73| Callouts | 100 | 100 | Yes |7475### Per-element cost approximation7677| Flow element | SOQL | DML | Notes |78|---|---|---|---|79| Get Records | 1 per element | 0 | Rows count against 50,000 rows |80| Create Records | 0 | 1 per element | Rows count against 10,000 |81| Update Records | 0 | 1 per element | Rows count against 10,000 |82| Delete Records | 0 | 1 per element | Rows count against 10,000 |83| Loop | 0 | 0 | Depends on what's inside |84| Assignment | 0 | 0 | Free |85| Decision | 0 | 0 | Free |86| Subflow | Inherited | Inherited | Counts against parent transaction |87| Action (invocable Apex) | Varies | Varies | Apex action's own SOQL + DML add up |8889**The key trap:** a Loop with a Get Records inside = 1 SOQL per loop iteration. 200 iterations = 200 SOQL = immediate limit breach.9091## Recommended Workflow92931. **Enumerate every DML-class element** in the flow (Get, Create, Update, Delete, subflow, action).942. **Map which elements are inside loops.** Loop + DML/SOQL inside is the #1 limit-breach pattern. Hoist outside the loop via collection-based DML.953. **Account for shared limits.** If the flow runs on Account save, it shares the 100-SOQL budget with all other Account triggers, VRs, Before-Save flows, After-Save flows, and sharing recalculation.964. **Run a budget check:** `(max_batch_size × per_record_cost) ≤ 0.7 × limit` — leave 30% headroom for other automations sharing the transaction.975. **If budget is tight, tune:** hoist SOQL/DML out of loops, consolidate Get Records with OR-filters, cache field values, split work across transactions (Scheduled Paths, Platform Events).986. **Pre-deployment benchmark.** In sandbox, exercise the flow with 200-record batches. Measure SOQL, DML, CPU via `Limits.getQueries()` wrapper in an Apex test.99100## Key patterns101102### Pattern 1 — Budget a record-triggered flow103104Context: flow fires on Account update. Expected batch size: 200 records.105106Elements:107- Get Records: related Contacts (1 SOQL, returns avg 5 Contacts per Account = 1000 rows).108- Loop over Contacts with Update Records inside. ← ALARM.109110Un-tuned cost per batch:111- SOQL: 1 (Get Records outside loop)112- Contact Update: 1000 DML statements (1 per contact inside loop)113114DML-statement limit: 150. Breach at the 150th Contact.115116Tuned:117- Outside the loop, collect Contact updates into a collection variable.118- Single Update Records (collection) = 1 DML statement, 1000 DML rows.119120Tuned cost: 1 SOQL + 1 DML, 1000 rows. Well under limits.121122### Pattern 2 — Shared-transaction forecasting123124Account trigger stack:125- Before-Save Validation (3 Get Records = 3 SOQL)126- Record-Triggered After-Save Flow A (2 Get Records + 1 Update = 2 SOQL + 1 DML)127- Record-Triggered After-Save Flow B (NEW — 4 Get Records + 1 Create = 4 SOQL + 1 DML)128- Existing Apex trigger (avg 15 SOQL + 3 DML per 200 records)129130Total per 200-record batch: 24 SOQL + 5 DML (200 rows).131Available: 100 SOQL, 150 DML, 10,000 DML rows.132Headroom: 76 SOQL (OK).133134Adding Flow B costs 4 SOQL + 1 DML from the shared pool. Fine here; if a fourth flow were to be added adding 10 more SOQL, the margin would shrink.135136### Pattern 3 — Async offload137138Same context but Flow B needs to do heavy enrichment (15 SOQL per record):139- Inline: 15 × 200 = 3000 SOQL. Breach.140- Async: mark Flow B's entry as "Run Asynchronously" (Scheduled Path +0 minutes). Fresh transaction per batch of 200 records; fresh 100-SOQL budget.141142Trade-off: ~1-5 minute delivery delay, new-transaction idempotency requirement.143144### Pattern 4 — CPU time tuning145146Large loops with Assignments and Decisions consume CPU. Pattern that works in a 10-record test breaches at 200 records:147148- Pre-compute lookups into a Map outside the loop (O(1) access inside).149- Avoid nested Loops; if you need Map-of-List shape, pre-compute outside.150- Move complex Formula evaluations out of inner Decisions.151152CPU time is the hardest limit to diagnose — symptoms are timeouts, not explicit limit errors.153154### Pattern 5 — Heap size management155156Loop that accumulates all results into a big collection:157- 50,000 sObjects × avg 1 KB each = 50 MB. Heap limit breached at ~6 MB (async: 12 MB).158- Tuning: process in chunks via Scheduled Paths, or use a pass-through filter (transform + DML per chunk, don't accumulate).159160## Bulk safety161162This skill IS the bulk-safety math skill. Rules:163- Never DML inside a Loop.164- Never SOQL inside a Loop.165- Never accumulate unbounded results into a collection.166- Budget for shared transaction — don't assume the flow owns the whole 100 SOQL.167168## Error handling169170Limit exceptions terminate the transaction. Fault paths can't catch `System.LimitException` — the flow has already exceeded. The only recovery is:171- Reduce element consumption (bulkification).172- Split across transactions (async).173- Reduce batch size upstream (if caller is controllable).174175## Well-Architected mapping176177- **Performance** — budgeting limits is performance engineering. A flow with 70% limit headroom survives load spikes; a flow at 95% breaks under the first busy day.178- **Reliability** — shared-transaction math is what predicts cascading failures. Adding "one more flow" to a busy stack without budget analysis is the classic way orgs become fragile.179180## Gotchas181182See `references/gotchas.md`.183184## Testing185186```apex187@IsTest188static void testFlowStaysUnderLimits() {189 // Prepare 200-record bulk scenario.190 List<Account> accounts = new List<Account>();191 for (Integer i = 0; i < 200; i++) {192 accounts.add(new Account(Name = 'Test ' + i));193 }194195 Test.startTest();196 insert accounts;197 Test.stopTest();198199 // Assert total transaction stayed under 0.7 × limits.200 System.assertTrue(Limits.getQueries() < 70, 'SOQL budget exceeded');201 System.assertTrue(Limits.getDMLStatements() < 105, 'DML budget exceeded');202}203```204205## Official Sources Used206207- Salesforce Developer — Execution Governors and Limits: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_limits.htm208- Salesforce Help — Flow Limits and Considerations: https://help.salesforce.com/s/articleView?id=sf.flow_considerations_limit.htm209- Salesforce Help — Trigger Order of Execution: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm210- Salesforce Architects — Performance Engineering: https://architect.salesforce.com/