Monday, April 19, 2021

Access Modifiers

 There are 7 access modifiers in Salesforce.

1. Private:- If you declare a class as a private it is only known to the block in which it is declared.

          Note:- By default all the inner classes are private.

2. Public:- If you declare a class as a public, this class is visible throughout your application and you can access the class anywhere inside the application.

3. Global:- If you declare a class as a global in a class then it is visible to all the apex class in the application or outside the application.

         Note:- If a method or a class(inner) is declare as global then the top level class also must be declared as global.

4. With Sharing:- If you declare a class as a with sharing, sharing rules given to the current user will be taken into the consideration and the user can access and perform the operations based on the permissions given to that user on objects and fields(field level security, sharing rules).

5. Without Sharing:- If you declare a class as a without sharing then this class runs in system mode  which means apex code has access to all the objects and fields irrespective of current users sharing rules, field level security and object permissions.

      Note:- 

       i) If the class is not declared as with sharing or without sharing then the class is by default taken as without sharing.

      ii) Both inner class and outer classes can be declared as with sharing.

      iii) If innerclass is declared as with sharing and top level class is declared as without sharing then by default entire context will run in with sharing context.

      iv) If a class is not declared as with | without sharing and if this class is called by another class in which sharing is enforced then both the class run with with sharing.

      v) Outer class is declared as with sharing and inner class is declared as without sharing then inner class runs in without sharing context only (Inner class don't take the sharing properties from outer class).

6. Virtual:- If a class is declared with keyword Virtual then this class can be extended(inherited) or this class methods can be overridden by using a class called overridden.

7. Abstract:- This calss contains Abstract methods.

No comments:

Post a Comment