function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
_sfdc_sfdc 

what is the difference between with sharing and without sharing keywords in apex?

Best Answer chosen by thisisnotapril
Pat PattersonPat Patterson
Use the with sharing or without sharing keywords on a class to specify whether or not to enforce sharing rules (https://help.salesforce.com/HTViewHelpDoc?id=security_about_sharing_rules.htm&language=en_US). For more information, see the section on the with and without sharing keywords in the Apex docs (http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#CSHID=apex_classes_keywords_sharing.htm|StartTopic=Content%2Fapex_classes_keywords_sharing.htm|SkinName=webhelp).

All Answers

Pat PattersonPat Patterson
Use the with sharing or without sharing keywords on a class to specify whether or not to enforce sharing rules (https://help.salesforce.com/HTViewHelpDoc?id=security_about_sharing_rules.htm&language=en_US). For more information, see the section on the with and without sharing keywords in the Apex docs (http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#CSHID=apex_classes_keywords_sharing.htm|StartTopic=Content%2Fapex_classes_keywords_sharing.htm|SkinName=webhelp).
This was selected as the best answer
Ashish_SFDCAshish_SFDC
Hi , 


To Simplify the explanation further : there are two modes in which apex executes - User Mode and System Mode . 

Where the code that Executes in User mode will keep the Sharing Model in mind and access only those records and objects which are available to the user. 

Where as the System mode executes irrespective of Sharing model. 

Based on generalisation Salesforce decided to have few components to execute in User mode by default and Few in System mode by default to change the default and have it our way we use With Sharing or Without Sharing Key words. 

Reply back if you have anything specific. 


Regards,
Ashish



ramesh babu 114ramesh babu 114

what is the difference between with sharing and without sharing keywords in apex?
 
farukh sk hdfarukh sk hd