You need to sign in to do that
Don't have an account?
GauravTrivedi
By Default which sharing rule will apply on Apex??
In class declaration if we don’t write keyword “with sharing” then it runs in system mode then why keyword “without sharing” is introduced in apex?
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_keywords_sharing.htm
All Answers
With/without sharing indicates whether the sharing rules for the currently logged in user should be applied when accessing records. The permissions of the currently logged in user are ignored regardless of with/without sharing, as the code is still running in system mode.
According to you by default it is with Sharing.
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_keywords_sharing.htm
I have still doubt if Run in system mode then what is difference between without sharing & system mode. Please explain.?
If any of (with/without) by default then why we have to write it or there may be difference between default and with/without..
Thanks
Ashok
Thus running in system context means you can view sobject types that your profile doesn't allow, but with sharing stops you seeing any records that haven't been shared with yout.
"
By default Apex code executes without checking permissions. Hence the code will not enforce field level security, sharing rules and user permissions during execution of Apex code in Triggers, Classes and Controllers. This creates the risk that unauthorized users may get access to sensitive data records or fields.
To prevent this, developers should use with sharing keyword when declaring their classes if the class has SOQL or SOSL queries or DML Statements. This will ensure that current user’s permissions, field level security and sharing rules are enforced during code execution. Thus users will only see or modify records and fields which they have access to.
Use without sharing when a specific class should have full access to records without taking into account current user’s permissions. This should be used very carefully.
Use inherited sharing when the code should inherit the level of access from the calling class. This is more secure than not specifying a sharing level as the default will be equivalent to "with sharing".
"