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
shailendra singhaishailendra singhai 

if in soql with apex class 10 fields we have with select. and using with sharing. will it fetch the data for the user who is not having who is restricted with field level security for the field

if in soql with apex class 10 fields we have with select. and using with sharing. will it fetch the data for the user who is not having  who is  restricted with field level security for the field
Khan AnasKhan Anas (Salesforce Developers) 
Hi Shailendra,

Greetings to you!

If you declare a class as a With Sharing, Sharing rules given to the current user will be taken into the consideration and the user can access or perform the operations based on the permissions given to him on object and fields (Field Level Security, Sharing rules).

The with sharing keyword allows you to specify that the sharing rules for the current user are considered for the class. The only exceptions to this rule are Apex code that is executed with the executeAnonymous call and Chatter in Apex.executeAnonymous always executes using the full permissions of the current user. 

Note: There is no guarantee that a class declared as with sharing doesn't call code that operates as without sharing. Class-level security is always still necessary. In addition, all SOQL or SOSL queries that use PriceBook2 ignore the with sharing keyword. All PriceBook records are returned, regardless of the applied sharing rules.

Please refer to the below links which might help you further.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_keywords_sharing.htm

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_security_sharing_rules.htm

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas