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.

2 Answers 2


http://success.salesforce.com/issues_view?id=a1p30000000SVY3AAO it's a known issue scheduled to be fixed in next patch release

  • Timing. I had just Googled my way to the same page. Looks like I can use Type.forName(string, string); in the short term. Nov 2, 2012 at 1:53
  • The Issues Index shows that this has been fixed success.salesforce.com/issues_view?id=a1p30000000SVY3AAO But when I try this, I'm still getting an exception. Have either of you tried it since and got it to work ? Nov 6, 2012 at 13:37

According to http://success.salesforce.com/issues_view?id=a1p30000000SVY3AAO 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=''.

  • 1
    Thanks Fernando, yes I got it to work with the Type.ForName('', LocalClassName), but the 'Fixed' status mislead me to believe that it was actually fixed. I wouldn't have expected to use a 'Workaround' for an Issue that was marked 'Fixed', if you see what I mean :) Nov 7, 2012 at 13:39

You must log in to answer this question.

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