Back to Top

Apex is by default with sharing or without sharing?

Posted on TimeMarch 6, 2026

 By default, Apex classes are without sharing, meaning they run in "system context" and ignore the current user’s record-level sharing rules, permissions, and field-level security. They have full access to all data, although they still respect organization-wide defaults.


Key Details regarding Default Behavior:


  • Without Sharing (Default): If neither with sharing nor without sharing is declared, the class runs in system mode, ignoring user sharing rules.
  • Inheritance: If an undeclared class is called by a with sharing class, it inherits that strict context.
  • Triggers: Triggers are also without sharing by default, running in system context.
  • Security Risk: Because the default is insecure, it is highly recommended to explicitly declare with sharing to enforce security rules.
  • AuraEnabled: @AuraEnabled classes can sometimes behave differently, but generally, they follow the same rules, necessitating explicit declaration.

0comments

Post a Comment