nerdexam
Salesforce

PDI · Question #210

In the following example, which sharing context will myMethod execute when it is invoked?

The correct answer is B. Sharing rules will be Inherited from the calling context. When an Apex method's sharing context is not explicitly defined, it inherits the sharing context of the class or method that invoked it.

Submitted by sofia.br· Apr 18, 2026Logic and Process Automation

Question

In the following example, which sharing context will myMethod execute when it is invoked?

Options

  • ASharing rules will not be enforced for the running user.
  • BSharing rules will be Inherited from the calling context.
  • CSharing rules will be enforced by the instantiating class.
  • DSharing rules will be enforced for the running user.

How the community answered

(70 responses)
  • A
    7% (5)
  • B
    87% (61)
  • C
    4% (3)
  • D
    1% (1)

Why each option

When an Apex method's sharing context is not explicitly defined, it inherits the sharing context of the class or method that invoked it.

ASharing rules will not be enforced for the running user.

This describes `without sharing` behavior, which is only explicit or inherited from a `without sharing` context.

BSharing rules will be Inherited from the calling context.Correct

By default, if an Apex class or method is not explicitly declared with `with sharing` or `without sharing`, its sharing rules are inherited from the calling context. This means if it's called by a `with sharing` class, it runs `with sharing`; if called by a `without sharing` class, it runs `without sharing`. If called from outside Apex (e.g., a trigger or a Visualforce page that is running `with sharing`), it runs `with sharing`.

CSharing rules will be enforced by the instantiating class.

Sharing rules are determined by the class definition (`with sharing`, `without sharing`) or inheritance, not solely by the "instantiating class" which isn't a standard concept for sharing context.

DSharing rules will be enforced for the running user.

This describes `with sharing` behavior, which is only explicit or inherited from a `with sharing` context. The default is not always enforced.

Concept tested: Apex class sharing context inheritance

Source: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_sharing.htm

Topics

#Apex Sharing#Inherited Sharing#Apex Security#with sharing/without sharing

Community Discussion

No community discussion yet for this question.

Full PDI Practice