function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
skr00skr00 

Access modifier

Hi All

 

Need to know the diff. between Private & Global access modifier. What you mean by variable is only visible locally (for Private) & variable is visible to Apex scripts (for global). Private, i understood.

 

• private—the variable is only visible locally. This setting is the default if no access modifier is specified. You can have a class nested within a class. By default, these nested classes are private, meaning they are only visible within the outer class.
• public—the variable is visible within your application.
• global—the variable is visible to all Apex scripts.

 

Regards,

 

Pri...

 

Andy BoettcherAndy Boettcher

You pretty much answered your own question.  =)

 

I'll take a more general stab...

 

  • Private = a variable that is only accessible from within the same APEX class or trigger where it was created.
  • Public = a variable that is accessible to ANY APEX class or trigger within your Salesforce instance's default namespace. 
  • Global = a variable that is accessible across namespaces - a more common use is for creating APEX webservices that can be consumed via Javascript Remoting or external websites.

 

(Namespaces = most commonly used when you install an AppExchange package into your org.  It seperates out "your" code from the application's code)

Ankit AroraAnkit Arora

A small additional points, which may be different from the actual answer but would like to share. Once you have used Global in any method and packaged the class in managed package you will then not be able to change the definition of method.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page