I am bit confused about
with sharing and
without sharing in Apex. I have set OWD to private for Contacts and created sharing rules. If I login as an Admin, I see all the contacts. If I login with a non admin user(NA) with a particluar role, I see contacts created by this user and contacts created by other users but with NA user's role (because of sharing settings). So if in an apex class with
omitted sharing (which behaves as
without sharing) I query for contacts I will only see limited number of contacts if the user who is calling this class is NA (I tested using a test class with
system.runAs with NA user). So my question is what is the point of
with/without sharing as in my case even with
omitted sharing, it seems to work as though it is working as
with sharing. It says here that
The with sharing keyword allows you to specify that the sharing rules for the current user are considered for the class. You have to explicitly set this keyword for the class because Apex code runs in system context.
but also says in the
Implementation Details About with sharing and without sharing Keywords section:
If a class isn’t declared as either with or without sharing, the current sharing rules remain in effect.