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
ashish jadhav 9ashish jadhav 9 

If I've a class without sharing option and a subclass with sharing option what will happen? Does it works?

What will happen when I declare a class without sharing and subclass with sharing option? What is the most essential parts of coding do I need to study in terms to be good in apex coding?
JyothsnaJyothsna (Salesforce Developers) 
Hi Ashish,

Use the with sharing keywords when declaring a class to enforce the sharing rules that apply to the current user

Use the without sharing keywords when declaring a class to ensure that the sharing rules for the current user are not enforced. 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.

Some things to note about sharing keywords:
  • The sharing setting of the class where the method is defined is applied, not of the class where the method is called. For example, if a method is defined in a class declared with "with sharing" is called by a class declared with "without sharing", the method will execute with sharing rules enforced.
  • If a class isn’t declared as either with or without sharing, the current sharing rules remain in effect. This means that the class doesn’t enforce sharing rules except if it acquires sharing rules from another class. For example, if the class is called by another class that has sharing enforced, then sharing is enforced for the called class.
  • Both inner classes and outer classes can be declared as with sharing. The sharing setting applies to all code contained in the class, including initialization code, constructors, and methods.
  • Inner classes do not inherit the sharing setting from their container class.
  • Classes inherit this setting from a parent class when one class extends or implements another.

Hope this helps you!
Best Regards,
ashish jadhav 9ashish jadhav 9
Thanks for the your valueable explanation Jyothsna, I'm really excited on this fouram as I've too many questions and getting such a nice response from experienced people like you :)

Can you please tell me whether apex workbook is enough to learn coding? As I'm new to this technology, I would like to know about the apex and VF, if I do both the workbook then Can I do basic coding in SFDC? Please guide me accordingly.

Thanks in advance.
DeepthiDeepthi (Salesforce Developers) 
Hi Ashish,

Along with following the Apex Workbook, you can go through the trailhead modules on Apex and Visualforce Pages, which gives you deep understanding on the Salesforce concepts. Kindly follow the links below to reach out to trailhead.

Let us know if you need any help!
Best Regards,
ashish jadhav 9ashish jadhav 9
Thank you so much Deepthi. Please let me know, whether I will be in a position to do coding in SFDC after this hands on from trailhead? Can I face the interview confidently with this approach?

How can I plan smartly to get in as a SFDC developer? Please guide as I'm new to it :)