PDI · Question #91
In the following example, which starting context will mymethod execute it is invoked?
The correct answer is A. Sharig rules will be inherited from the calling context. This question pertains to the execution context of a method, specifically how sharing rules are applied when an Apex method is invoked without explicit sharing keywords.
Question
In the following example, which starting context will mymethod execute it is invoked?
Options
- ASharig rules will be inherited from the calling context.
- BSharig rules will be enforced for the running user.
- CSharig rules will be enforced by the instartiating class.
- DSharig rules will not be enforced for the running user.
How the community answered
(27 responses)- A89% (24)
- B7% (2)
- C4% (1)
Why each option
This question pertains to the execution context of a method, specifically how sharing rules are applied when an Apex method is invoked without explicit sharing keywords.
By default, an Apex method executes with the sharing rules of the calling context, meaning it inherits the user's data visibility and access permissions from the code that invoked it.
Sharing rules are not always enforced for the running user if the calling context is set to 'without sharing' or if the method itself is explicitly 'without sharing'.
Sharing rules are determined by the execution context, not by the instantiating class itself.
Sharing rules are typically enforced for the running user; the default behavior is to inherit the caller's sharing context, which usually includes enforcement.
Concept tested: Apex sharing context inheritance
Source: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_keywords_sharing.htm
Topics
Community Discussion
No community discussion yet for this question.