I have two Apex classes A and B. A is OuterClass which is called B so that will be an InnerClass. A is running in with sharing context and B is running without sharing context. Now B has a method inside it, So in which context will that method be running?
TechnicalSenior Salesforce DeveloperSalesforce DeveloperThe method in class B will run in without sharing context. This is because inner classes in Apex inherit the sharing context of the outer class only for the purposes of accessing records. Since class A runs with sharing, it enforces sharing rules when accessing records, but class B, being defined without sharing, does not enforce those rules when executing its own methods.
This means that the method can access all records, regardless of the user's sharing settings, which is crucial for operations that require full data access.