The 'inherited sharing' keyword on an Apex class, which allows the class to run in the sharing mode of the class that called it.
1.Using Inherited sharing enables you to pass AppExchange Security Review
and ensure that your privileged Apex code is not used in unexpected or insecure ways.
2. Inherited sharing ensures that the deafult is to run as with sharing.
3.Inherited sharing runs as with sharing when used as a Lightning component controller,
a visualforce controller, an Apex REST service or any other entry point to an Apex transaction.
4. A class declared as inherited sharing runs as without sharing only when explicitly called from an already
established without sharing context.
ex :
public without sharing class noSharing {
public void callwithoutsharingclassmethod(){
inheritedSharingClass iobj=new inheritedSharingClass();
List<Contact> conlst=iobj.getAlltheContacts();
}
}
public inherited sharing class inheritedSharingClass {
public List<Contact> getAlltheContacts(){
return [SELECT Id,Name FROM Contact];
}
}
No comments:
Post a Comment