function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
xxyyzzxxyyzz 

Dynamically execute batch classes

I have a requirement where I need to be able to pass the name of a batch apex class to a function as a string. The function will then call Database.ExecuteBatch using the string as the name of the class.

 

E.G.

 

public void executeBatch(String className, String parameter1){

    //This is where I am stuck
    className classToExecute = new className(parameter1);

    Database.ExecuteBatch(classToExecute, 5);

}

 How do I dynamically create an instance of the class?

UVUV

I dont think this would be possible in Apex..