Aller au contenu

Run Context, and Who May Run Them

Ce contenu n’est pas encore disponible dans votre langue.

Module 6 of 7 in the chapter Sharing When Writing Apex: Secure Code, chapter 17 of Securing Salesforce: Sharing and Visibility. Each module stands on its own.

The question this module answers: A flow reads and writes data like code does, but it’s built by clicks. Who does a flow run as, how much can it see, and who is allowed to run it?

Everything in modules 1 to 5 has a flow version. A flow is code an admin builds, and like Apex it can run as the user or skip the user’s access. The difference is where you look: not a keyword at the top of a class, but a setting in the flow’s advanced properties. That’s easy to miss in a review, which is exactly why it gets a module.

Who the flow runs as: it depends how it starts

Section titled “Who the flow runs as: it depends how it starts”

“Flows run in user context or system context.” In user context, the running user’s profile and permission sets decide object and field access; in system context, running with or without sharing decides the data access (Flow Run Context (opens in a new tab), Salesforce Help, checked 2026-11-26).

And by default, the context comes from how the flow is launched. Salesforce’s table, in short (same page):

  • User context: an Experience Cloud site, a Lightning page, a custom button or link, a flow action, the REST API, a web tab, a flow embedded in a Visualforce page or an Aura component. (Salesforce’s table doesn’t yet have a row for a flow embedded in a Lightning web component with the lightning-flow component, which the Lightning Component Reference (opens in a new tab) describes as representing “a screen flow interview in Lightning runtime” (checked 2026-11-26, and still no row on 2026-11-23). Until it has one, test the run context of a flow embedded that way before you rely on it.)

  • System context without sharing: record-triggered, schedule-triggered and platform event–triggered flows (and processes built in Process Builder).

  • Depends on the code: a flow started from Apex.

Notice the pattern. The flows a user starts on purpose run as the user. The flows that run automatically run without sharing, just like triggers in module 5. Chapter 11 met this when a flow writes share records (chapter 11, module 6).

One line from the same page belongs on every site project: “When a flow runs in system context, it runs in that context for all users, including users with the Guest User profile.”

You can override the default. In Flow Builder, “In the How to Run the Flow dropdown, select a context” (Set Flow Run Context (opens in a new tab), Salesforce Help, checked 2026-11-26). The four options, in Salesforce’s words:

  • User or System Context: “The context is determined by how the flow is launched.”
  • User Context—Enforces User Permissions: “The flow always runs with the running user’s access level, even if its caller runs in system context. This option is available for screen flows and autolaunched flows on API version 68.0 and later.”
  • System Context with Sharing: “The flow respects org-wide default settings, role hierarchies, sharing rules, manual sharing, teams, and territories. But it doesn’t respect object permissions, field-level access, or other permissions of the running user.”
  • System Context without Sharing: “The flow can access all data.”

Two of those deserve a second look.

System Context with Sharing is half a lock. It’s the flow version of a with sharing class running in system mode (module 1): the right records, but every field on them, whatever the user’s field-level security says. If a screen shows those fields, the user sees fields their profile hides.

User Context—Enforces User Permissions is new in Winter ‘27. Here’s the problem it fixes: “By default, a flow in user context can inherit elevated permissions from a system-context caller, such as another flow or Apex. If a caller running in system context invokes your user-context flow, your flow also runs in system context” (Flow Run Context). With the new option, “a flow configured with this option always runs with user-level access, giving you predictable security boundaries and full control over your flow’s access level” (Winter ‘27 (API Version 68.0) (opens in a new tab), Salesforce Help, checked 2026-11-26). It’s the flow equivalent of module 3’s user mode: the flow decides its own access, whoever calls it.

Salesforce’s own advice on system context

Section titled “Salesforce’s own advice on system context”

Salesforce has a page just for this, and it starts with a warning: “Screen flows and autolaunched flows without triggers can expose more data than intended. This potential issue primarily affects Experience Cloud sites accessed by external users” (Data Safety When Running Screen and Autolaunched Flows in System Context (opens in a new tab), Salesforce Help, checked 2026-11-26). Its advice, which is module 2’s narrow elevation in flow form (same page):

  • Run screen flows as the user. “Run screen flows in user context whenever possible, because it enforces permissions that restrict user access to data.”
  • Elevate one step, not the whole flow. “Instead of setting the entire screen flow to run in system context, use the Subflow element to launch a flow that performs actions that require permissions beyond what the running user has.”
  • Store only the fields you need. In a system-context flow, choose “Choose fields and let Salesforce do the rest” instead of “Automatically store all fields,” so that “Salesforce stores only the fields you need, reducing the number of fields that are exposed to users.”

On the restaurant ordering site from chapter 15, that means: the booking screen runs as the site user; the one step that counts every restaurant’s deliveries in a slot is a small system-context subflow that returns a yes or no; and nothing on the screen ever holds another restaurant’s order.

Four ways a flow can run Four ways a flow can run. User or System Context, the default: decided by how the flow starts; screen flows, sites, buttons and the API run as the user; record-triggered, scheduled and platform event flows run in system context without sharing. User Context, Enforces User Permissions, new in Winter '27 at API 68.0: always the user's access, even when the caller runs in system context; for screen and autolaunched flows. System Context with Sharing, half a lock: the user's records, but no object or field checks. System Context without Sharing, no lock: all data, for guests too on a site. Footnote: run screen flows as the user, and elevate only the one step that needs it, in a subflow. {"author": "Steve Simpson", "blueprint": "1.0.0", "builder": "standard 1.59.0", "built": "2026-11-20", "id": "DGM-SVA-SC-06", "rights": "\u00a9 2026 Twinshark LLC. All rights reserved.", "template": "comparison 0.5.0", "theme": "stevetecharc 1.4.0"} User or System Context the default Decided by how the flow starts Screen flows, sites, buttons, API: as the user Record-triggered, scheduled, platform event: system, without sharing User Context, Enforces User Permissions Winter '27, API 68.0 Always the user's access Even when the caller runs in system context Screen and autolaunched flows System Context with Sharing half a lock The user's records No object or field checks System Context without Sharing no lock All data For guests too, on a site Run screen flows as the user, and elevate only the one step that needs it, in a subflow. © 2026 Twinshark LLC · stevetecharc.com
Click to enlarge

The other half of the question is who can start the flow at all (Limit User Access to Run Flows (opens in a new tab), Salesforce Help, checked 2026-11-26).

The Run Flows permission. “Assign the Run Flows permission to control which users can run flows directly, including screen flows from the UI and autolaunched flows that run in user context, such as flows launched from Apex, Lightning pages, or APIs.” Users need it to “Run screen flows,” “Run autolaunched flows that run in the user context,” “Pause or resume flow interviews,” and “Complete orchestration and approval work items.” And “In Setup, the Run Flows permission is an app permission and not a system permission.”

Automatic flows don’t need it. “System-triggered flows (record-triggered, platform event-triggered, and schedule-triggered) run automatically and don’t require the initiating user to have the Run Flows permission.” Whatever the type, the running context still needs the object, field and record permissions to finish.

Per-flow access. “For individual flows that you create or clone, you can override default behavior and restrict access to users with enabled profiles or permission sets only.” That’s the flow version of a permission on an Apex class: not everyone who can run flows can run this one.

Guests. Chapter 14 already gave the rule: “If guest users aren’t using flows, disable the Run Flows permission” (chapter 14, module 2). For the guest profile, Salesforce adds that “You can control access to specific flows for the Guest User profile only through the profile page” (Limit User Access to Run Flows).

Test knowledge. Know that flows run in user or system context, decided by default by how they’re launched: screen flows, sites, buttons, Lightning pages and the REST API as the user; record-triggered, schedule-triggered and platform event–triggered flows in system context without sharing. Know the four run options, that System Context with Sharing respects sharing but not object or field permissions, that a user-context flow can inherit system context from its caller, and that User Context—Enforces User Permissions (screen and autolaunched flows, API 68.0) prevents it. Know the Run Flows permission (an app permission), that system-triggered flows don’t need it, and per-flow access by profile or permission set. A likely area, not a known question.

  • For every flow that touches data: its run context, and why, recorded like a sharing keyword.
  • That screen flows on sites run as the user, with any elevation in a small system-context subflow that returns only what the screen needs.
  • Where System Context with Sharing is used, which fields it shows that the user’s field-level security would hide.
  • Which flows should use User Context—Enforces User Permissions, so a system-context caller can’t widen them.
  • Who holds Run Flows, which flows have per-flow access, and that the guest profile runs only the flows it must.

Beyond the exam: what AI changes. Flows are one of the commonest kinds of agent action, and the agent’s user runs them. A flow in system context without sharing gives the agent everything; a screen-style flow left at the default can inherit system context from whatever calls it. For flows built as agent actions, User Context—Enforces User Permissions is the setting to reach for first. Chapter 20 covers agents.