What is the difference between global and public access modifier in apex? I tried googling but still not able to understand.. Any example will be most helpfull.. Thanks

1 Answer 1


PUBLIC means the class/method/variable is visible to all code in your namespace

GLOBAL means the class/method/variable is visible to all code in any namespace

So if you're aren't developing managed packages there isn't much difference. If you are developing managed packages you'll use GLOBAL when you want to expose classes/methods/variables to the org that installed your package. And consequently, you would be held to keeping those classes/methods/variables available in future versions as your subscribers may have started referencing. Where as public classes/methods/variables you can remove at your leisure since you know the subscriber org won't have any references to them.

There used to be some edge cases for automated process (i.e. batches had to be global), but most of these are no longer required. However templates for batches still seem to imply you have to use global.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .