6

I'm looking to dynamically instantiate a class by its name. How can I do that in Apex? I thought about a factory method with a series of if-else statements, but am not satisfied with that as it isn't a general solution.

1 Answer 1

8

It seems something like that is possible with:

System.Type objType = Type.forName(objName);
Object obj = objType.newInstance();
1
  • 5
    Please note that it has to have an empty constructor in order to do so. May 2, 2013 at 12:19

You must log in to answer this question.

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