Do I need to define sharing for inner classes?

In preparation to Security Review I am checking that all my classes follow instructions from Sharing in Apex Classes.

Now I am wondering do inner classes also need to be defined as with sharing | without sharing | inherited sharing to pass the security review?


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

According to Using the with sharing, without sharing, and inherited sharing Keywords (emphasis mine):

  • 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.

So yes, you need to declare sharing for each inner class as well.

Method 2

Above all, you need to define sharing mode for inner classes separately, since they are separate classes in terms of inheritance.

you may use inherited sharing since winter 19 to avoid issues

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x