Access
Modifiers:
I.private: if you declare a class a private is it only know to the block in which it is declared.
→ by default all the inner classes are private.
II.Public: if you declare class as a public, these class is a visible throughout your application and you can access the application anywhere.
III.Global: if you declare the class a global this apex class is visible to all the apex applications in the application or outside the application.
Note: if a method of class (inner) is declare as global then the top level class also must be declared as global.
IV.With sharing: if you declare a class as a with sharing, sharing rules given to the correct uses will be taken in to the consideration and uses can access & perform the operations based on the permissions given to him on objects & fields. (filed level security, sharing rules).
V.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 uses 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
- Both inner classes and out as classes can be declared as with sharing.
- If inner class is declared as without sharing. Then by default entire context will run in with sharing context.
- 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 classes run with sharing.
- Out as class is declared as with sharing and inner class is declared as without sharing context only. [inner classes is don’t take the (sharing properties) from out as class].
- 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 over ridden.
- Abstract: these class contains abstract methods.
Ex 1:
Public class out as class
{
//code
Class inner class
{
//inner
class code
}
}
Ex 2:
Public with sharing class sharing
class
{
//code
}
Ex 3:
Public without sharing class no
sharing
{
//code
}
Ex 4:
Public with sharing class out as
{
//out as class code
Without sharing class inners
{
//inner class code
}
}
In the above code out as class runs
with current us as sharing rules. But inner class runs with system context.
Ex 5:
Pubic without sharing out as
{
//out as class code
With sharing class inner
{
// inner class code
}
}
In these both inner and out as classes
runs with current uses permissions.
No comments:
Post a Comment