Wednesday, September 23, 2020

Salesforce Apex Access Modifiers

Access Modifiers 

Private: 

  • If you declare a class as a private, it is only known to the block in which it is declared.
  • By default all the inner classes are private.

Public:

  • If you declare a class as a public, this apex class is visible throughout your application and you can access the application anywhere.

Global:

  • If you declare a class as a global, this apex class is visible to all the apex application in the application or outside the application.
  • Note: If a method or a class (inner) is declared as global then the top level class also must be declared as global.

With Sharing:

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

Without Sharing:

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

  • Note: If the class is not declared as With Sharing or Without Sharing then the class is by default taken as Without Sharing.
  • Both inner class and outer classes can be declared as With Sharing.
  • If inner class is declared as With Sharing and top-level class is declared as without sharing, then the entire context will run in With Sharing context.
  • 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 classes don't take the sharing properties from outer class).

Virtual:

  • If a class is declared with keyword Virtual then this class can be extended (Inherited) or this class method can be overridden by using a class called overridden.

Abstract:

  • This class contains Abstract methods, which will provide common method implementation to all subclasses.

No comments:

Post a Comment

ES12 new Features