Triggers and the API 67.0 Upgrade
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Module 5 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 trigger can’t have a sharing keyword. What changed inside triggers at API 67.0, and what can happen when a team raises a class or trigger to the new version?
Triggers are the code nobody calls on purpose. A user saves a record, an integration loads a thousand, a site user places an order, and the trigger runs, for all of them. That’s why they matter so much here. And Summer ‘26 changed them in a way that’s easy to miss, because the trigger itself didn’t change at all.
Outside: always without sharing
Section titled “Outside: always without sharing”“Apex triggers now always run in a without sharing context. Previously, nested triggers enforced sharing rules in certain edge cases” (Apex Triggers Always Run in a “without sharing” Context (opens in a new tab), Salesforce Summer ‘26 Release Notes, checked 2026-11-26). And you can’t change it: “Apex triggers can’t have an explicit sharing declaration” (Use the with sharing, without sharing, and inherited sharing Keywords (opens in a new tab), Apex Developer Guide, checked 2026-11-26).
That part applies in every API version.
Inside: user mode, from 67.0
Section titled “Inside: user mode, from 67.0”Here’s the change. “In API version 67.0 and later, database operations within trigger bodies, including SOQL queries, SOSL queries, DML statements, and Database methods, run in user mode unless system mode is explicitly specified.” User mode overrides the trigger’s without sharing context, so the body effectively runs with sharing (Apex Triggers Always Run in a “without sharing” Context).
So a trigger is without sharing on the outside and, at 67.0, effectively with sharing on the inside, unless the code says otherwise. Salesforce’s own example puts the two queries side by side: one with no mode, which “defaults to WITH USER_MODE” and returns the contacts the user can see; and one with WITH SYSTEM_MODE, where “Record sharing remains governed by the trigger’s own without sharing context, so all records are visible regardless of the user running the query” (same page).
Why this catches teams
Section titled “Why this catches teams”Read that against the triggers you already have. A trigger is written to do something on the user’s behalf, often to records the user can’t see:
- A roll-up. A restaurant’s staff save an order, and a trigger totals every order on the account. At 66.0, the query sees every order. Raised to 67.0 with no mode, it sees only the orders this user can see, and the total is quietly wrong.
- An update to a related record. The trigger stamps a date on the account, which a site user can only read. At 67.0, in user mode, that save can fail.
- Share logic. Chapter 11’s record trigger and user trigger write share rows for other people (chapter 11, module 5). Code like that exists precisely to do what the user can’t. Don’t assume it still works in user mode; test it.
None of these are bugs in Salesforce. They’re the secure default doing what it says. The risk is a team raising a version to get a new feature, and finding out in production.
Here’s the roll-up done on purpose, as a sketch (not compiled):
trigger OrderTotals on Order (after insert, after update) { OrderTotalsHandler.recalculate(Trigger.new);}
public without sharing class OrderTotalsHandler { // Reason for without sharing and system mode: the account total must // count every order on the account, not only those this user can see. public static void recalculate(List<Order> changed) { Set<Id> accountIds = new Set<Id>(); for (Order o : changed) { accountIds.add(o.AccountId); } List<AggregateResult> totals = [SELECT AccountId, SUM(TotalAmount) amount FROM Order WHERE AccountId IN :accountIds WITH SYSTEM_MODE GROUP BY AccountId]; // ...write the totals to the accounts, as system, with the same reason }}Two habits are visible there: the logic lives in a handler, and the mode is explicit with its reason beside it. Both are Salesforce’s own advice: “To control behavior reliably independent of the API version, set explicit access mode on all database operations in your trigger and handler classes. When possible, delegate all business logic to trigger handlers” (Apex Triggers Always Run in a “without sharing” Context).
Raising the version, safely
Section titled “Raising the version, safely”API versions are per class and per trigger, so an org doesn’t upgrade all at once. Somebody raises one, usually to use something new. Here’s the plan I’d ask for before anyone does:
- Know what you have. List every class and trigger with its API version, and every one that touches data.
- Remove what won’t compile. “Apex classes set to API version 67.0 and later that include WITH SECURITY_ENFORCED don’t compile” (The WITH SECURITY_ENFORCED SOQL Clause is Removed (opens in a new tab), Salesforce Summer ‘26 Release Notes, checked 2026-11-26). Replace it with
WITH USER_MODE. - Make the old behavior explicit first. Add a sharing keyword to every class and a mode to every database operation, matching what it does today. Then raising the version changes nothing, because nothing relies on a default.
- Decide each exception on purpose. Where the old code ran in system mode only by default, ask whether it should. Many queries should become user mode. The ones that must stay system mode get a reason.
- Test as real users. Not as an administrator. As a sales user, a site user, the integration user, with
System.runAsin tests (chapter 13, module 3): one who should see the result, one who shouldn’t, and check the roll-ups and related saves come out right for both.
Step 3 is the one that matters most. Once every class says its keyword and every operation says its mode, the API version stops being a security question.
Test knowledge. Know that triggers always run without sharing and can’t declare a keyword; that from API 67.0 the database operations in a trigger body run in user mode unless system mode is explicit, effectively enforcing with sharing inside the trigger; and that WITH SYSTEM_MODE in a trigger sees all records under the trigger’s without sharing context. Know Salesforce’s advice: explicit access modes on every operation in triggers and handlers, and business logic delegated to handlers. Know that classes using WITH SECURITY_ENFORCED don’t compile at 67.0. A likely area, not a known question.
What an architect decides here
Section titled “What an architect decides here”- Who may raise a class or trigger’s API version, and that it goes through the plan, not a quick edit.
- That every trigger delegates to a handler with an explicit keyword, and every operation states its mode.
- Which trigger work must see more than the user (roll-ups, related updates, share logic), and the reason written beside each system-mode line.
- The users the upgrade is tested as: the least-privileged ones, the site users, the integration user.
Beyond the exam: what AI changes. Agents save records too, and every save fires the triggers. At 67.0, a trigger with no explicit mode runs its queries as the agent’s user. If that user has narrower access than the people who usually save those records, totals and related updates can come out differently for the agent. Put the agent’s user on the upgrade test list. Chapter 20 covers agents.
Explore
Section titled “Explore”- Apex Triggers Always Run in a “without sharing” Context (opens in a new tab), Salesforce Summer ‘26 Release Notes (checked 2026-11-26)
- The WITH SECURITY_ENFORCED SOQL Clause is Removed (opens in a new tab), Salesforce Summer ‘26 Release Notes (checked 2026-11-26)
- Use the with sharing, without sharing, and inherited sharing Keywords (opens in a new tab), Apex Developer Guide (checked 2026-11-26)
