Salesforce Flow & Automation Development
Design and build production-grade Salesforce Flows and automation with correct governor
limit awareness, proper bulkification, appropriate trigger type selection, and robust
error handling.
Before Designing Any Automation
Determine the automation type. Ask what triggers the automation if not specified:
- Record change → Record-Triggered Flow (before-save, after-save, or async)
- User interaction → Screen Flow
- Time-based → Schedule-Triggered Flow or Scheduled Path on Record-Triggered Flow
- External event → Platform Event-Triggered Flow
- Multi-step process with human tasks → Flow Orchestrator
- Approval workflow → Approval Process (or Flow Orchestrator for complex cases)
Read reference/record-triggered/record-triggered-flows.md for record-triggered patterns
or reference/flow-builder/screen-flows.md for screen flow patterns.
Determine before-save vs after-save (for record-triggered flows):
- Before-save: Only modifying the triggering record's fields → no DML cost, fastest
- After-save: Creating/updating related records, sending emails, calling external services
- Run asynchronously: Heavy processing, callouts, operations that can be eventually consistent
Read reference/record-triggered/record-triggered-flows.md for the decision matrix.
Check the order of execution to understand when your flow runs relative to
validation rules, Apex triggers, and other automations:
Read reference/common-patterns/order-of-execution.md.
Plan for bulk operations. Any flow triggered by data loads, imports, or Apex
batch jobs processes up to 200 records per transaction. Design flows that work
correctly for both single-record and bulk operations:
Read reference/common-patterns/governor-limits-and-bulkification.md.
Record-Triggered Flow Quick Reference
Before-Save (fastest, no DML cost)
Use when: Modifying only the triggering record's fields
Runs: Before validation rules, before DML commit
DML cost: None (field assignments only)
Can do: Set field values on triggering record
Cannot do: Create/update/delete other records, send emails, call Apex
After-Save (most common)
Use when: Need to create/update related records, send notifications, call Apex
Runs: After DML commit of triggering record
DML cost: Normal (each Create/Update/Delete = 1 DML statement)
Can do: Everything — CRUD on any object, emails, invocable actions, subflows
Cannot do: Modify triggering record without additional DML (use before-save instead)
Run Asynchronously
Use when: Callouts, heavy processing, operations that don't need immediate consistency
Runs: In a separate transaction after the original transaction commits
DML cost: Separate governor limit context (fresh limits)
Can do: Callouts, long-running operations
Cannot do: Block the user's save operation
Governor Limits in Flow
These limits apply per transaction — know them before designing any flow:
| Limit |
Number |
What Triggers It |
| SOQL queries |
100 |
Each Get Records element = 1 query |
| DML statements |
150 |
Each Create/Update/Delete Records = 1 DML |
| Records retrieved (SOQL) |
50,000 |
Total across all Get Records |
| Records processed (DML) |
10,000 |
Total across all Create/Update/Delete |
| Flow elements executed |
2,000 |
Per flow interview (not per transaction) |
| CPU time |
10,000 ms |
Sync; 60,000 ms async |
| Callouts |
100 |
Per transaction |
The #1 Flow anti-pattern: DML inside a loop. If your flow loops over 200 records
and each iteration has a Create Records element, that's 200 DML statements — over the
150 limit. Fix: Use collection variables to accumulate records, then do one Create
Records element after the loop.
Read reference/common-patterns/governor-limits-and-bulkification.md for patterns.
Approval Processes
When building approval workflows:
- Entry criteria determine which records enter the process — use formula for complex logic
- Approval steps define who approves and in what order
- Actions fire at specific stages: initial submission, approval, rejection, recall
- Records are locked during approval by default
- Trigger from Flow using the "Submit for Approval" core action
Read reference/approval-processes/approval-processes.md for the full setup guide.
Screen Flow Patterns
When building interactive flows:
- Choose the right run context: user context (default) respects sharing; system context
bypasses sharing (use carefully)
- Use reactive screens for dynamic visibility and conditional components
- Custom LWC screen components need the
flow:availableForFlowScreens interface
- Distribute via Lightning pages, quick actions, utility bar, or Experience Cloud
Read reference/flow-builder/screen-flows.md for patterns.
Error Handling
- Always add fault connectors on DML and callout elements
- Use the Custom Error element (Winter '24+) for user-friendly error messages in
record-triggered flows
- Fault paths receive
{!$Flow.FaultMessage} with the error detail
- Consider rollback behavior: after-save flow failures roll back the entire transaction
Flow Metadata & Deployment
- Flows are stored as
.flow-meta.xml in force-app/main/default/flows/
- Only one version can be active at a time
- Deploy via
sf project deploy start — include the flow metadata file
- Test flows in sandbox before activating in production
- Use Flow Test (Setup → Flow Test) for automated testing of autolaunched/record-triggered flows
Reference Docs
Read the relevant reference doc BEFORE designing automation:
| Topic |
File |
| Record-Triggered Flows (before/after save, async) |
reference/record-triggered/record-triggered-flows.md |
| Order of Execution |
reference/common-patterns/order-of-execution.md |
| Governor Limits & Bulkification |
reference/common-patterns/governor-limits-and-bulkification.md |
| Screen Flows |
reference/flow-builder/screen-flows.md |
| Flow Elements & Resources Reference |
reference/flow-builder/elements-and-resources.md |
| Flow Metadata XML Quick Reference |
reference/flow-builder/flow-metadata-reference.md |
| Approval Processes |
reference/approval-processes/approval-processes.md |
| Scheduled & Autolaunched Flows |
reference/scheduled-autolaunched/scheduled-and-autolaunched-flows.md |
| Platform Event-Triggered Flows |
reference/platform-events/platform-event-flows.md |
| Flow Orchestrator |
reference/orchestrator/flow-orchestrator.md |
| Flow Security Model (run context, sharing) |
reference/common-patterns/flow-security-model.md |
| Null Handling (null vs blank vs empty) |
reference/common-patterns/null-handling.md |
| Flow Testing & Debugging |
reference/common-patterns/flow-testing.md |
| Flow Deployment & Versioning |
reference/common-patterns/flow-deployment.md |
| Common Pitfalls (top 25) |
reference/common-pitfalls.md |
Checklists
Offer relevant checklists when the user is building or deploying automations:
| Checklist |
File |
| New Flow design & deployment |
checklists/new-flow-checklist.md |
| Approval Process setup |
checklists/approval-process-checklist.md |
Templates
Use these as starting points when generating flow metadata:
| Pattern |
Directory |
| Record-Triggered Flow (before-save + after-save) |
templates/record-triggered-flow/ |
| Screen Flow (record edit with input variable) |
templates/screen-flow/ |
| Scheduled Flow (daily batch update) |
templates/scheduled-flow/ |
| Platform Event-Triggered Flow |
templates/platform-event-flow/ |
| Approval Process (.approvalProcess-meta.xml) |
templates/approval-process/ |
1---2name: sf-flow-automation3description: Build and configure Salesforce Flows and automation including Record-Triggered Flows, Screen Flows, Scheduled Flows, Approval Processes, Platform Event-Triggered Flows, and Flow Orchestrator. Use this skill whenever the user mentions Salesforce Flow, Flow Builder, record-triggered flow, before-save flow, after-save flow, screen flow, approval process, scheduled flow, autolaunched flow, platform event flow, flow orchestrator, flow governor limits, flow bulkification, DML in loop, flow error handling, fault path, flow formula, invocable action, flow subflow, flow variable, flow collection, approval step, approval action, or any automation design on the Salesforce platform. Also trigger when the user asks about order of execution, flow best practices, flow deployment, flow testing, flow debugging, or migrating from Process Builder or Workflow Rules to Flow. Even if the user just says "automate this process" or "build a flow for this," use this skill.4---56# Salesforce Flow & Automation Development78Design and build production-grade Salesforce Flows and automation with correct governor9limit awareness, proper bulkification, appropriate trigger type selection, and robust10error handling.1112## Before Designing Any Automation13141. **Determine the automation type.** Ask what triggers the automation if not specified:15 - **Record change** → Record-Triggered Flow (before-save, after-save, or async)16 - **User interaction** → Screen Flow17 - **Time-based** → Schedule-Triggered Flow or Scheduled Path on Record-Triggered Flow18 - **External event** → Platform Event-Triggered Flow19 - **Multi-step process with human tasks** → Flow Orchestrator20 - **Approval workflow** → Approval Process (or Flow Orchestrator for complex cases)2122 Read `reference/record-triggered/record-triggered-flows.md` for record-triggered patterns23 or `reference/flow-builder/screen-flows.md` for screen flow patterns.24252. **Determine before-save vs after-save** (for record-triggered flows):26 - **Before-save**: Only modifying the triggering record's fields → no DML cost, fastest27 - **After-save**: Creating/updating related records, sending emails, calling external services28 - **Run asynchronously**: Heavy processing, callouts, operations that can be eventually consistent2930 Read `reference/record-triggered/record-triggered-flows.md` for the decision matrix.31323. **Check the order of execution** to understand when your flow runs relative to33 validation rules, Apex triggers, and other automations:34 Read `reference/common-patterns/order-of-execution.md`.35364. **Plan for bulk operations.** Any flow triggered by data loads, imports, or Apex37 batch jobs processes up to 200 records per transaction. Design flows that work38 correctly for both single-record and bulk operations:39 Read `reference/common-patterns/governor-limits-and-bulkification.md`.4041## Record-Triggered Flow Quick Reference4243### Before-Save (fastest, no DML cost)44```45Use when: Modifying only the triggering record's fields46Runs: Before validation rules, before DML commit47DML cost: None (field assignments only)48Can do: Set field values on triggering record49Cannot do: Create/update/delete other records, send emails, call Apex50```5152### After-Save (most common)53```54Use when: Need to create/update related records, send notifications, call Apex55Runs: After DML commit of triggering record56DML cost: Normal (each Create/Update/Delete = 1 DML statement)57Can do: Everything — CRUD on any object, emails, invocable actions, subflows58Cannot do: Modify triggering record without additional DML (use before-save instead)59```6061### Run Asynchronously62```63Use when: Callouts, heavy processing, operations that don't need immediate consistency64Runs: In a separate transaction after the original transaction commits65DML cost: Separate governor limit context (fresh limits)66Can do: Callouts, long-running operations67Cannot do: Block the user's save operation68```6970## Governor Limits in Flow7172These limits apply per transaction — know them before designing any flow:7374| Limit | Number | What Triggers It |75|---|---|---|76| SOQL queries | 100 | Each Get Records element = 1 query |77| DML statements | 150 | Each Create/Update/Delete Records = 1 DML |78| Records retrieved (SOQL) | 50,000 | Total across all Get Records |79| Records processed (DML) | 10,000 | Total across all Create/Update/Delete |80| Flow elements executed | 2,000 | Per flow interview (not per transaction) |81| CPU time | 10,000 ms | Sync; 60,000 ms async |82| Callouts | 100 | Per transaction |8384**The #1 Flow anti-pattern: DML inside a loop.** If your flow loops over 200 records85and each iteration has a Create Records element, that's 200 DML statements — over the86150 limit. Fix: Use collection variables to accumulate records, then do one Create87Records element after the loop.8889Read `reference/common-patterns/governor-limits-and-bulkification.md` for patterns.9091## Approval Processes9293When building approval workflows:94951. Entry criteria determine which records enter the process — use formula for complex logic962. Approval steps define who approves and in what order973. Actions fire at specific stages: initial submission, approval, rejection, recall984. Records are locked during approval by default995. Trigger from Flow using the "Submit for Approval" core action100101Read `reference/approval-processes/approval-processes.md` for the full setup guide.102103## Screen Flow Patterns104105When building interactive flows:1061071. Choose the right run context: user context (default) respects sharing; system context108 bypasses sharing (use carefully)1092. Use reactive screens for dynamic visibility and conditional components1103. Custom LWC screen components need the `flow:availableForFlowScreens` interface1114. Distribute via Lightning pages, quick actions, utility bar, or Experience Cloud112113Read `reference/flow-builder/screen-flows.md` for patterns.114115## Error Handling116117- Always add fault connectors on DML and callout elements118- Use the Custom Error element (Winter '24+) for user-friendly error messages in119 record-triggered flows120- Fault paths receive `{!$Flow.FaultMessage}` with the error detail121- Consider rollback behavior: after-save flow failures roll back the entire transaction122123## Flow Metadata & Deployment124125- Flows are stored as `.flow-meta.xml` in `force-app/main/default/flows/`126- Only one version can be active at a time127- Deploy via `sf project deploy start` — include the flow metadata file128- Test flows in sandbox before activating in production129- Use Flow Test (Setup → Flow Test) for automated testing of autolaunched/record-triggered flows130131## Reference Docs132133Read the relevant reference doc BEFORE designing automation:134135| Topic | File |136|---|---|137| Record-Triggered Flows (before/after save, async) | `reference/record-triggered/record-triggered-flows.md` |138| Order of Execution | `reference/common-patterns/order-of-execution.md` |139| Governor Limits & Bulkification | `reference/common-patterns/governor-limits-and-bulkification.md` |140| Screen Flows | `reference/flow-builder/screen-flows.md` |141| Flow Elements & Resources Reference | `reference/flow-builder/elements-and-resources.md` |142| Flow Metadata XML Quick Reference | `reference/flow-builder/flow-metadata-reference.md` |143| Approval Processes | `reference/approval-processes/approval-processes.md` |144| Scheduled & Autolaunched Flows | `reference/scheduled-autolaunched/scheduled-and-autolaunched-flows.md` |145| Platform Event-Triggered Flows | `reference/platform-events/platform-event-flows.md` |146| Flow Orchestrator | `reference/orchestrator/flow-orchestrator.md` |147| Flow Security Model (run context, sharing) | `reference/common-patterns/flow-security-model.md` |148| Null Handling (null vs blank vs empty) | `reference/common-patterns/null-handling.md` |149| Flow Testing & Debugging | `reference/common-patterns/flow-testing.md` |150| Flow Deployment & Versioning | `reference/common-patterns/flow-deployment.md` |151| Common Pitfalls (top 25) | `reference/common-pitfalls.md` |152153## Checklists154155Offer relevant checklists when the user is building or deploying automations:156157| Checklist | File |158|---|---|159| New Flow design & deployment | `checklists/new-flow-checklist.md` |160| Approval Process setup | `checklists/approval-process-checklist.md` |161162## Templates163164Use these as starting points when generating flow metadata:165166| Pattern | Directory |167|---|---|168| Record-Triggered Flow (before-save + after-save) | `templates/record-triggered-flow/` |169| Screen Flow (record edit with input variable) | `templates/screen-flow/` |170| Scheduled Flow (daily batch update) | `templates/scheduled-flow/` |171| Platform Event-Triggered Flow | `templates/platform-event-flow/` |172| Approval Process (.approvalProcess-meta.xml) | `templates/approval-process/` |