You need to sign in to do that
Don't have an account?
Please answer me
what is the with sharing and without sharing in apex ?can any one provide small example with brief description???
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
- public with sharing class A {}
- public without sharing class B{}
- public class C{} // Class C is a non-specified-sharing class.
Now, let's consider the following case scenarios:More Info:- https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_keywords_sharing.htm
All Answers
Note: Mark this as solution if this helps!
Default - Without Sharing
Now, Apex class always execute in system context i.e. Apex code has access to all objects and fields irrespective of the logged in User.
Example - lets consider you have VF page in which you are showing certain fields as columns. Lets see one column says "Sales Rep Performance" which displays a flag in red, green and yellow. Now ideally this field should not be visible whenever a Sales Rep accesses this page (consider this as business requirement).
But it is always visible if the class has no keyword specified or if a class has without sharing specified.
Now once the class is "with sharing" the object permissions, field-level security, sharing rules are applied for the current user and fields which should not be visible/accessible and not visible or accessible.
Important -
Hope this gives good understanding ?
- public with sharing class A {}
- public without sharing class B{}
- public class C{} // Class C is a non-specified-sharing class.
Now, let's consider the following case scenarios:More Info:- https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_keywords_sharing.htm