#SalesforceSummer26 [Tip 28] - Apex Classes Now Default to With Sharing

Quick question: if you write an Apex class and don't add "with sharing" or "without sharing," what happens to your users' sharing rules?

For years the answer was uncomfortable — the class ran in "without sharing" mode by default, ignoring org-wide defaults and sharing rules, and letting the running user see records they normally couldn't. Forget the declaration, and your class quietly had more access than you intended.

Summer '26 changes the default. On API version 67.0 and later, an Apex class with no sharing declaration now defaults to "with sharing" — so it respects your org-wide sharing settings and custom sharing rules out of the box.

To bypass sharing, you now have to say so explicitly with "without sharing." Salesforce calls this "secure by default": the safe behavior is what you get when you don't specify.

Product Area: Apex

// ----------------------------------------------------------
// 1. NEW DEFAULT BEHAVIOR (API 67.0+, no explicit declaration)
// This class has no sharing keyword, so as of API 67.0 it
// implicitly behaves like "with sharing" — sharing rules ARE enforced.
// ----------------------------------------------------------
public class AccountLookupDefault {
    public static List<Account> getAllAccounts() {
        // A running user will only see Accounts they have access to,
        // even though no "with sharing" keyword was written.
        return [SELECT Id, Name, OwnerId FROM Account];
    }
}

// ----------------------------------------------------------
// 2. EXPLICIT "with sharing" (recommended going forward)
// Makes the intent clear regardless of API version.
// ----------------------------------------------------------
public with sharing class AccountLookupSecure {
    public static List<Account> getAllAccounts() {
        return [SELECT Id, Name, OwnerId FROM Account];
    }
}

// ----------------------------------------------------------
// 3. EXPLICIT "without sharing" (opt-in bypass)
// Needed only when you intentionally want the class to
// ignore sharing rules and see all records, e.g. for a
// batch job or trusted utility class.
// ----------------------------------------------------------
public without sharing class AccountLookupAllRecords {
    public static List<Account> getAllAccounts() {
        // Bypasses sharing rules on purpose — every Account is returned
        // no matter who is running the code.
        return [SELECT Id, Name, OwnerId FROM Account];
    }
}

When you recompile a class on API 67.0, a query that used to see every record may now honor sharing and return fewer.

So before you bump the version, decide where you genuinely need "without sharing" and declare it. The best habit here is simple — always state the sharing mode explicitly, and never leave it to the default at all.

References & Useful URLs

  • For Related Summer '26 Release Note Article – Click Here