Sub topic 3
Who the Flow Runs As and What It Can Access
Assume you know Salesforce objects, fields, records, Setup, and basic declarative automation. The key question is not only what a flow does, but which permissions apply when it runs.
Run context and access
A flow’s run context controls record visibility and permissions. User context applies the running user’s access. System context can let the flow access records the user cannot normally see. Sharing behavior depends on the flow type and its configured run mode.
Use the least powerful context that meets the requirement. A scheduled flow commonly runs without a user at the keyboard, so test access to every object and field it reads or changes.
Bulk data and governor limits
Salesforce governor limits restrict database queries, updates, and other work in one transaction. Design for many records even if today’s test uses one.
- Get records once and store them in a collection.
- Loop through the collection in memory.
- Add changed records to a second collection.
- Update the collection after the loop.
- Do not place Get Records, Create Records, or Update Records inside a loop unless the small, fixed size is guaranteed.
Fault paths
Connect a fault path from database actions and other elements that can fail. Store $Flow.FaultMessage in a log record, notify an administrator, or route the error to a useful recovery step. Scheduled flows cannot show a screen, so logging and notification matter.
A fault path handles the failure; it does not automatically fix invalid data or undo external actions. Make the recovery path safe to run again.
Versions, monitoring, and deployment
Save a new version when changing active automation. Activate only the tested version. Existing callers use the active version unless they explicitly reference another version.
Use Flow Builder’s Debug option with representative inputs. Check failed flow interviews, error emails, debug logs, and scheduled jobs when investigating a failure. Record the flow API name, version, failed element, and fault message.
Flow metadata is XML that describes elements, variables, connections, and settings. Retrieve it from one org and deploy it to another with Salesforce CLI or change sets. Activation is a separate operational step, so confirm the intended version is active after deployment.
Choosing the automation
| Need | Suitable choice |
|---|---|
| Reusable logic called by code or another flow | Autolaunched flow |
| Repeated processing at a defined time | Schedule-triggered flow |
| Complex algorithms or very high-volume processing | Scheduled Apex |
A scheduled flow is easier to maintain for straightforward record work. Choose scheduled Apex when the logic needs advanced control, complex error handling, or processing beyond flow limits.
Exercise
Why should a flow update a record collection after a loop instead of updating each record inside the loop?
Show answer
This reduces database operations and helps the flow stay within Salesforce governor limits.