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
ScriptMonkeyScriptMonkey 

Accessing Classes that are in a Managed Package

I'm looking to Access someting inside a Managed Package from outside of it, in a visualforce page.

 

Brief details:

Package A has all the apex code, and is fully functional on its own, but has no "customer facing" pages.  Person who installs this package uses it all with an admin panel.  Package A is managed.

 

Package B is unmanaged, and includes only a few files, visualforce pages that will use the classes inside the package as controllers/functions.

 

I am able to access visualforce pages and resources with "Package_A__pagename" etc, but cannot access the apex class in the controller attribute in the apex:page tag.

 

Any advice how to do what I'm trying to do?

 

Matt

mtbclimbermtbclimber

Package "A" must declare it's methods as "global" which establishes a contract between it and it's consumers, i.e. the unmanaged package "B".  This prevents package "A" from introducing a change that would break package "B".  If you want to utilize services/functionality embedded within the apex code of the managed package then you need to convince the owner of that package to establish an API by making global methods.  

ScriptMonkeyScriptMonkey

 


mtbclimber wrote:

Package "A" must declare it's methods as "global" which establishes a contract between it and it's consumers, i.e. the unmanaged package "B".  This prevents package "A" from introducing a change that would break package "B".  If you want to utilize services/functionality embedded within the apex code of the managed package then you need to convince the owner of that package to establish an API by making global methods.  


 

Thank you so much for your answer.  The class in Package A is global, do all the methods within it need to be global as well, or just the ones being called from outside?  To answer the next question, calling Package_A__class gives me the error "Apex Class xyz Does Not Exist" when I try to save in eclipse.

 

I'm the author of both packages, so changes can be made to either.

mtbclimbermtbclimber

Yes, the class and the methods need to be global, as does the argument and response types of the methods themselves if not primitives.  Everything that is part of the API contract needs to be flagged as "global".

ScriptMonkeyScriptMonkey

 


mtbclimber wrote:

Yes, the class and the methods need to be global, as does the argument and response types of the methods themselves if not primitives.  Everything that is part of the API contract needs to be flagged as "global".


 

Thank you very much for your help.  Before I spend the time to go through and change all the declarations and repackage the "A" package, can you confirm that not being global explains why:

<apex:page controller="Package_A__class"> says "class does not exist"

(the class currently IS global, just not every method in it.)

 

Matt

ScriptMonkeyScriptMonkey

I changed all the methods to be global, but I still get the error:

 

Apex Class 'Project_A__Class' does not exist.

 

based on this line:

 

<apex:page cache="false" controller="Project_A__Class" showHeader="false" standardStylesheets="false">

mtbclimbermtbclimber

Sorry I didn't reply before. I believe this is a syntax issue. Namespaces on Apex classes utilize a different delimiter, try this in your page:

 

 

<apex:page cache="false" controller="Project_A.Class" showHeader="false" standardStylesheets="false">

 

Anything you access from your page in a separate namespace will need to be global so depending on what your page does you may have needed the global modifiers on more than the class anyway.

 

ScriptMonkeyScriptMonkey

Thank you. Problem A fixed, now on to B....

 

It's now saying Constructor is not visable, but it's global as is the class...

 

ScriptMonkeyScriptMonkey

nevermind that. I forgot to change the version number that the file was dependant on.  now I'm working through other issues, but the major "can't see it" is solved.

 

Thank you so much for your help.

ISVforce PartnerISVforce Partner
Altough you found the solution, I would like to post the format by which a global class can be called externally:

namespace_prefix.class.method(args)

More info here: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_namespace_prefix.htm