What is the difference between with sharing, without sharing, and inherited sharing?
Suggested answer
with sharing: The class enforces the running user's record-level sharing (OWD, role hierarchy, sharing rules). SOQL queries and DML operations only affect records the user has access to. without sharing: The class ignores sharing — all records of the object are accessible regardless of the user's sharing access. Use for system-level operations where full data access is explicitly required. inherited sharing: The class inherits the sharing mode of its caller. If called from a with sharing class, it runs with sharing; if called from a without sharing context, it runs without sharing. This is the safest default for utility/service classes that should respect the caller's context. If no keyword is specified, the class defaults to inherited sharing (in most contexts) — but explicitly declaring is a best practice.
Practice content for interview preparation; not an official vendor answer. Verify details against current product documentation.
Community comments (0)
No comments yet.
Sign in or create a free account to add a comment. Comments are moderated before they appear.