Study for the Salesforce Platform Developer Exam. Study with flashcards and multiple choice questions, each question has hints and explanations. Get ready for your exam!

Practice this question and more.


What is an accurate statement about the with sharing keyword in Apex?

  1. Inner class do not inherit the sharing setting from the container class

  2. Both inner and outer class can be declared as with sharing

  3. Either inner class or outer classes can be declared as with sharing but not both

  4. Inner class inherit the sharing setting from the container class

The correct answer is: Inner class do not inherit the sharing setting from the container class

The correct statement regarding the "with sharing" keyword in Apex is that inner classes do not inherit the sharing settings from their containing (outer) class. This means that if an outer class is declared with the "with sharing" keyword, the inner class does not automatically adopt that sharing behavior and can run in system context, which would allow it to access all data regardless of sharing rules. Understanding how the "with sharing" keyword behaves in the context of class hierarchies is key in Apex development. The use of "with sharing" ensures that the operations performed within the class respect the sharing rules defined in the organization, limiting access to records accordingly. However, an inner class, when defined, has its scope and can have its own sharing rules defined or none at all, independent of the outer class. This understanding is essential for effectively managing data access and ensuring that security measures in the Salesforce platform are upheld in custom development work using Apex.