Salesforce Decode
Salesforcedecode
Back to questions
ApexAdvancedsharingsecuritywithout-sharing

Explain when without sharing is justified and how to audit elevated access

Real World Scenario

Developer added without sharing to fix partner visibility bug. Security audit flags uncontrolled data exposure across 12 classes.

Expected Answer

• without sharing only for system operations: rollups, sharing calc, integration enrichment • Document justification per class in security registry • Narrow elevated logic into single service class not entire controller • Never without sharing on @AuraEnabled user-facing entry points without review • Audit log elevated access operations with business justification code • Quarterly review of without sharing classes against active use cases • Prefer manual share creation over blanket without sharing visibility

Follow-Up Questions & Answers

Click to expand — each follow-up includes a direct, interview-ready answer

Main difference: use case and scale. without sharing only for system operations: rollups, sharing calc, integration enrichment. Document justification per class in security registry. Pick based on your integration pattern and team capability. without sharing spreads like debt—centralize and audit or security review will fail. Optimize for scale and operational observability.

Architect Perspective

without sharing spreads like debt—centralize and audit or security review will fail.