4

I'm trying to pass a class name from a subscriber org up into a managed package, to make the package extensible. The package is going to use Type.forName(namespace, classname) to create an instance of the local class.

I've read this question:

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

Which says that I just need to make sure that I include a blank string for the namespace, but that's not working for me.

Inside my managed package, I have:

global static Type forName(String namespace, String className) {
    return Type.forName(namespace, className);
}

Then, I try to call this from anonymous apex in the subscriber org:

System.debug(Type.forName('', 'PardotEmailTemplateWorker'));
System.debug(Nebula_API.NebulaApiWorker.forName('', 'PardotEmailTemplateWorker'));

Resulting in:

10:12:25.063 (63913068)|USER_DEBUG|[1]|DEBUG|PardotEmailTemplateWorker
10:12:25.065 (65727007)|USER_DEBUG|[2]|DEBUG|null

Any idea how I can move forward from here?

10

I'm an idiot: my local class, PardotEmailTemplateWorker, was not global.

Setting it to global solved the problem.

Hopefully, this will stand as a lesson to someone else in the future :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.