You need to sign in to do that
Don't have an account?
David Wright
What is the real impact of using the "global" keyword in a class definition?
I'm having trouble understanding what the global keyword actually does does in Apex. I know what the docs say, so I'm not looking for anyone to spit that out. The docs say:
"The global access modifier declares that this class is known by all Apex code everywhere. All classes that contain methods defined with the webService keyword must be declared as global. If a method or inner class is declared as global, the outer, top-level class must also be defined as global."
The phrase "...known by all Apex code everywhere." is confusing to me, and possibly even a little scary. Is it suggesting that using the global keyword allows your code to be visible across other orgs (literally ALL apex code, at least for that SFDC instance), or is it just visible to all apex in your org, and if so, how is that different from simply using the public keyword?
"The global access modifier declares that this class is known by all Apex code everywhere. All classes that contain methods defined with the webService keyword must be declared as global. If a method or inner class is declared as global, the outer, top-level class must also be defined as global."
The phrase "...known by all Apex code everywhere." is confusing to me, and possibly even a little scary. Is it suggesting that using the global keyword allows your code to be visible across other orgs (literally ALL apex code, at least for that SFDC instance), or is it just visible to all apex in your org, and if so, how is that different from simply using the public keyword?
The access modifier really has nothing to do with the source code visibility by the way. Declaring a class to be Global won't make the the source code visible by a 3rd party (for instance, your favorite app publisher). It simply means if the code in those app namespaces wants to invoke the available Global methods in your code, it could.
My question is more about whether the functions are somehow invokable across all of apex globally, or if it's restricted within your org. From your answer, it seems like the only real purpose of its usage (besides the required usage for web services) would be for app developers to allow their code to be invoked outside of their apps namespace. I figured that was the case.
Still leaves an unanswered question (based on hazy wording in the documentation) about exactly how far global goes. Is it only applied to the apex (Accross all namespaces) within one org, or does it cross org boundaries?