Sub topic 9
Run context, permissions, and data access
This chapter assumes you know Flow Builder basics, Salesforce objects and fields, and how permission sets work in Setup. It covers what a flow-based action is allowed to read and change when an agent calls it.
Why the run context matters
An agent calls your flow on behalf of someone. The flow's run context decides whose access the flow uses for object permissions, field-level security, and record sharing. The agent's language model cannot widen that access. It only supplies input values. So the safest design limits the flow itself.
The two run contexts
A flow runs in one of two modes. You set this in Flow Builder under the flow's advanced settings ("How to Run the Flow").
| Mode | Object and field permissions | Record sharing | Typical use |
|---|---|---|---|
| User or system context with sharing | Not enforced by default for flow elements. | Enforced | Reads that must respect record visibility |
| System context without sharing | Not enforced | Not enforced | Narrow lookups the user could not otherwise see |
Treat the table as a starting point and check the current options in your org's Flow Builder, because the labels and the defaults for field-level security differ between releases. In general, a flow does not enforce object or field permissions on its own, so your design has to do it.
Who is the running user
The running user depends on how the agent is deployed. An employee-facing agent usually runs as the employee who is chatting. A service agent often runs as a designated agent user, and that user's profile and permission sets decide what the flow can reach. Confirm which one applies to your agent before you rely on sharing rules.
Limiting the data the flow touches
Apply least privilege in three places.
- Permissions. Give the running user, or the agent user, a permission set with access only to the objects and fields the action needs. For a case-status lookup, that means read access to Case and to the Status and Case Number fields.
- Query scope. In Get Records, filter tightly. Match on the exact Case Number and fetch only the fields you need. Avoid "all records" queries.
- Output. Return only what the customer should see. In the earlier example, the
caseStatusoutput returns one status string and not the full case record.
Validating inputs inside the flow
The agent passes in whatever text the user gave. Treat it as untrusted. If a user supplies a case number that belongs to someone else, a system-context flow will return that case's status. Add a check in the flow, for example a Decision that confirms the case's contact matches the verified customer, before you return any data. Do not rely on the action instructions to prevent this, since instructions guide the model but do not enforce access.
Common errors
- Using system context for convenience. The flow works in testing as an admin, then exposes data in production.
- Testing only as an admin. Admins have broad access, so a missing permission never shows. Test as the actual running user.
- Returning whole records. Extra fields leak data and add noise for the model.
- Forgetting the agent user's permission set. The flow fails with an access error that the agent then reports as "something went wrong".
Exercise
A flow-based action looks up a case by number and runs in system context without sharing. Name two changes that reduce the risk of exposing another customer's case.
Show answer
Any two of: add a Decision that verifies the case belongs to the verified customer before returning data; switch to a context that enforces sharing if the running user can already see the needed records; filter Get Records tightly and return only the status field; limit the agent user's permission set to the Case fields the action needs.