If you specify inherited sharing Keyword on an Apex class, which allows the class to run in the sharing mode of the class that called it. Using inherited sharing enables you to pass security review and ensure that your privileged Apex code is not used in unexpected or insecure ways.
- An Apex class with inherited sharing runs as with sharing when used as a Visualforce page controller, Apex REST service, or an entry point to an Apex transaction.
- An Apex class with Inherited Sharing is being called from some other class which is having without sharing setting, then it will run in without sharing mode.
Example
This example declares an Apex class with inherited sharing and a Visualforce invocation of that Apex code. Because of the inherited sharing declaration, only opportunities for which the running user has sharing access are displayed. If the declaration is omitted, even opportunities that the user has no rights to view are displayed due to the insecure default behavior of omitting the declaration.
Apex Class
Happy Learning!!
Apex Class
public inherited sharing class OpportunityMethods {
public list<Opportunity> getAllTheOpps(){
return [SELECT Id, Name, StageName FROM Opportunity];
}
}
Visualforce page<apex:page controller="OpportunityMethods">
<apex:repeat value="{!getAllTheOpps}" var="record">
{!record.Name}
</apex:repeat>
</apex:page>
Happy Learning!!
No comments:
Post a Comment