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
brahmi kamineni 11brahmi kamineni 11 

where we can use without sharing must and should in controller? I want scenarios why because i got that question in interview

NagendraNagendra (Salesforce Developers) 
Hi Brahmi,

Without Sharing is reserved for cases where the User does not have access to the records, but there is a need to update them based on user input.

Please let us know if any further clarification is required.

Thanks,
Nagendra
D-CoderD-Coder
Use the with sharing or without sharing keywords on a class to specify whether or not to enforce sharing rules.
The with sharing keyword allows you to specify that the sharing rules for the current user be taken into account for a class. You have to explicitly set this keyword for the class because Apex code runs in system context. In system context, Apex code has access to all objects and fields— object permissions, field-level security, sharing rules aren’t applied for the current user. This is to ensure that code won’t fail to run because of hidden fields or objects for a user. 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.

Use the without sharing keywords when declaring a class to ensure that the sharing rules for the current user are notenforced. For example, you may want to explicitly turn off sharing rule enforcement when a class acquires sharing rules when it is called from another class that is declared using with sharing.

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

If this answers your query please mark this question as a solved so that it can be filtered out from unsolved questions.