Where to use public...
 
Notifications
Clear all

[Solved] Where to use public, private and global access modifiers in Salesforce Apex?

2 Posts
1 Users
0 Likes
595 Views
Posts: 192
 CWL
Admin
Issue starter
(@cwl)
Member
Joined: 11 years ago

Difference between public/private/global variables in Apex.

Issue Tags
1 Reply
Posts: 192
 CWL
Admin
Issue starter
(@cwl)
Member
Joined: 11 years ago

Private: This is the default and means that the method or variable is accessible only within the Apex. If you do not specify an access modifier, the method or variable is private.

Protected: This means that the method or variable is visible to any inner classes in the defining Apex class, and to the classes that extend the defining Apex class. You can only use this access modifier for instance methods and member variables.

Public: This means the method or variable can be used by any Apex in this application or namespace.

Global: This means the method or variable can be used by any Apex code that has access to the class, not just the Apex code in the same application. This access modifier should be used for any method that needs to be referenced outside of the application, either in the SOAP API or by other Apex code. If you declare a method or variable as global, you must also declare the class that contains it as global.

Check out this link: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_access_modifiers.htm

Reply
Share: