Inherited Sharing is a Salesforce Apex keyword that makes a class run with the sharing mode of the code calling it. When the class is the entry point, it runs as with sharing. It avoids accidental without sharing execution that exposes records a user should not see, but it enforces record access only, not object or field permissions.
How Inherited Sharing Works in Apex
Inherited sharing is a class-level sharing declaration that tells Salesforce Apex to adopt the sharing context of the caller. That makes it a safer default for reusable code, because the same class can behave appropriately when invoked from user-facing entry points, asynchronous paths, or other Apex classes without hardcoding a fixed sharing stance.
In practice, inherited sharing is most useful when a class might be called from multiple contexts and you want it to respect the surrounding execution model rather than forcing a universal access mode. If the class is the entry point, it behaves like with sharing, which helps reduce the chance that developers unintentionally expose records through an overly permissive class declaration.
What It Does and What It Does Not Control
Inherited sharing controls record-level sharing enforcement. It does not grant broader privileges and it does not replace object-level or field-level authorization. A class can still need separate checks for CRUD and FLS, and safe code often combines inherited sharing with explicit access validation where data is read or written.
This distinction matters because many Salesforce security bugs come from assuming that sharing alone is enough. A class may respect record visibility and still fail to prevent access to fields or objects that the current user should not be able to use. Inherited sharing is therefore a context-preserving control, not a complete authorization model.
Why It Matters in Reusable Salesforce Code
Inherited sharing is often the best fit for shared utility classes, service layers, and helper code that should follow the caller’s intent. It reduces the maintenance burden of deciding between with sharing and without sharing in every reusable component, while still preserving user-context record visibility when the class is reached from a user-facing path.
That makes it especially valuable in codebases where the same method may be called by Lightning entry points, triggers, or other Apex services. When used well, it helps keep access behavior predictable across call chains instead of silently widening record access because a downstream class was written too broadly.
For teams building secure Apex, Salesforce Apex and Lightning Secure Coding Guide is the natural companion for the surrounding coding patterns, including sharing keywords, user mode, and access validation.
Common Failure Modes and Defensive Use
The main failure mode is treating inherited sharing as a complete security boundary. It is not. If code performs SOQL, DML, or service logic that depends on object or field restrictions, the class still needs deliberate enforcement of those checks. Another common mistake is assuming inherited sharing is always equivalent to with sharing, when the effective behavior depends on who called the class and how the invocation started.
Defensively, inherited sharing works best when the development standard is clear: use it for code that should respect the caller’s record visibility, then layer explicit checks where business logic requires object, field, or operation-specific controls. That keeps the sharing model aligned with least privilege without making every reusable class context-specific by hand.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP ASVS, NIST SP 800-53 Rev 5 and CIS Controls v8 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP ASVS | V8 — Authorization | Inherited sharing affects record-level authorization behavior in Apex. |
| Recommendation — Verify record-access decisions separately from object and field authorization. | ||
| NIST SP 800-53 Rev 5 | AC-6 — Least Privilege | Inherited sharing helps preserve the caller's record visibility and limit exposure. |
| Recommendation — Apply AC-6 to keep Apex code from widening access beyond the caller's need. | ||
| CIS Controls v8 | CIS-5 — Account Management | Apex sharing choices affect who can see and act on business records. |
| Recommendation — Review application access paths so record visibility stays aligned with user need. | ||
Related resources from NHI Mgmt Group
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on November 26, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org