0

How can we conclude that using public modifier in the apex code enables us to call them anywhere within the application or namespace but not outside the application or namespace.Consider I'm not having any namespace in my org, so how it prevents calling the method from another application. Application in the sense do we mean App ?.

1 Answer 1

0

Well if you read the salesforce documentation, it clearly states -

public - This means the method or variable can be used by any Apex in this application or namespace. In Apex, the public access modifier is not the same as it is in Java. This was done to discourage joining applications, to keep the code for each application separate. In Apex, if you want to make something public like it is in Java, you need to use the global access modifier.

The best example I can think of is the scenario when you install a managed package. None of the methods or classes are visible/accessible to you even though they have been defined as public and that is because it is in a separate namespace than your org. You will only have visibility/access to a class or method which has been explicitly defined as global inside a managed package.

Edit: As for unmanaged packages, you can access them through code and even through the UI you can see that the classes are visible/editable, and the reason is because components in unmanaged packages do not have any Namespace Prefix. So technically, it is not a different "app", in order for it to be one it has to be managed with a separate Namespace

2
  • Hi @Jitender thank you for the answer.I agree, but consider we are installing a unmanaged package which will not have any namespace and yet it is a different app and we have access to the apex class present in the unmanaged package. My question is can't we call the public method present in the class of unmanaged package from our code though the method is present in class that belongs to another app? Commented Oct 24, 2017 at 8:35
  • @PrasanthSrinivasan Yes you can access them, through code and even through the UI you can see that the classes are visible/editable, and the reason is because components in unmanaged packages do not have any Namespace Prefix. So, technically it is not a different "app", in order for it to be one, it has to be managed with a separate Namespace. Commented Oct 24, 2017 at 8:59

You must log in to answer this question.

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