Managed package can’t access class defined in subscriber org via Type.forName

I’m in the process of making a managed package extensible via an Apex plugins pattern. Basically there is an interface defined in the managed package that the subscriber Orgs can implement and then provide the class name to the managed package via a custom setting. The managed package creates an instance of the subscriber orgs class, casts it to the interface and then invokes the required interface methods.

I’m following the examples from New Apex Type Methods in Summer ’12 and Making your managed package extensible with Apex Plugins

It’s all working, except calls to Type.forName('subscriberClassName') from within the managed package always return null for classes outside of the managed package.

It appears that the managed package can’t create an instance of the class in the subscriber org. Any ideas?

  • If I use the class name of a default implementation from within the managed package (ManagedNS.Plugings.OpportunityUpdatedDefaultImplementation) the code works fine.
  • The subscriber class and methods are all marked global.
  • Within the subscriber Org I can use anonymous apex to create both the subscriber class and the default implementation defined within the managed package. I have no problems using anonymous apex to invoke the interface methods.
    Type t = Type.forName('subscriberClassName');
    ManagedNS.Plugins.IOpportunityUpdated instance = (ManagedNS.Plugins.IOpportunityUpdated)t.newInstance();

    Type t2 = Type.forName('ManagedNS.Plugings.OpportunityUpdatedDefaultImplementation');
    ManagedNS.Plugins.IOpportunityUpdated instance2 = (ManagedNS.Plugins.IOpportunityUpdated)t2.newInstance();
  • The subscriber Org class subscriberClassName has version settings to the correct version of the beta managed package.


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1 it’s a known issue scheduled to be fixed in next patch release

Method 2

According to the issue has been fixed and I can confirm that it works. @techtrekker please note that the “fix” involves a workaround which is replacing Type.forName(String className) by Type.forName(String namespaceName,String className), and when the class is outside the package and local, the argument namespaceName=”.

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x