By default APEX runs in system mode - without sharing mode
with sharing :
without sharing:
inherited sharing: forced sharing / This allows the class to run in the same mode as the class which called it. Apex classes with Inherited Sharing that are called from other classes with no sharing settings will run in no sharing mode.
1) method defined class sharing setting is applied ,not of called class
2) both inner or outer class can be defined as sharing/without
- 3) Classes inherit sharing setting from a parent class when one class extends or implements another.
- 4) Apex triggers can’t have an explicit sharing declaration and run as without sharing.
- If a class with
without sharingis calling the method of a class withinherited sharing, then it will run inwithout sharingmode. - If a class with
with sharingis calling the method of a class withinherited sharing, then it will run inwith sharingmode. - If a class with
omitted sharing(i.e. no sharing is mentioned) is calling the method of a class withinherited sharing, then it will run inwithout sharingmode as the default sharing mode of theomitted sharingis to run inwithout sharingmode (This is because the calling class is established as awithout sharingcontext). A class declared asinherited sharingruns aswithout sharingonly when explicitly called from an already establishedwithout sharingcontext. - If a class with
with sharingis calling a method of a class withomitted sharingwhich in turn calls a method of a class withinherited sharing, then it will run inwith sharingmode, as the calling class is inwith sharingmode and omitted class is established aswith sharingcontext. - If a class with
without sharingis calling a method of a class withomitted sharingwhich in turn calls a method of a class withinherited sharing, then it will run inwithout sharingmode, as the calling class is inwithout sharingmode and the omitted class is established aswithout sharingcontext. - If the class is used as the entry point to an Apex transaction, an
omitted sharingdeclaration runs aswithout sharing. - If the class is used as the entry point to an Apex transaction,
inherited sharingensures that the default is to run aswith sharing.
- The sharing setting of the class where a method is defined is applied, not of the class where the method is called from. For example, if a method is defined in a class declared as with sharing is called by a class declared as without sharing, the method executes with sharing rules enforced.


No comments:
Post a Comment