Find your content:

Search form

You are here

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.

Attribution to: Daniel Ballinger

Possible Suggestion/Solution #1

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=''.

Attribution to: Fernando

Possible Suggestion/Solution #2 it's a known issue scheduled to be fixed in next patch release

Attribution to: mjgallag
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content