private static void scheduleTEst(Set<Id> sObjectId, String cronJobDetailName, String className, Integer hour) {
List<CronTrigger> scheduledExecs = [SELECT Id, CronJobDetail.Name, NextFireTime,
State, StartTime, EndTime, CronExpression,
TimesTriggered
FROM CronTrigger
WHERE CronJobDetail.Name = :cronJobDetailName
AND State = 'WAITING'];
if(scheduledExecs.isEmpty()) {
//Getting time.
Datetime setTime = Datetime.now();
System.Type objType = Type.forName(className);
Object o = objType.newInstance();
//Setting time.
Datetime newSetTime = setTime.addHours(hour);
//To String.
String batchHour = String.valueOf(newSetTime.hour());
//CronExpression. The format is:
//Seconds Minutes Hours Day_of_month Month Day_of_week
String sch = '0 0 ' + batchHour +' * * ?';
//Setting schedule.
System.schedule( className + ' Schedule', sch , o); //This line throws an error.
}
}
I can save this code because I have following error:
Method does not exist or incorrect signature: void schedule(String, String, Object) from the type System
I tried to use a NEW specific batch class name (for example, 'OpportunityBatch newOppB = new OpportunityBatch()'), and it accepts it as a parameter. Why it does not accept passed the newInstance of object as a paremeter? Is there any way to do it without requirement of specify a singular class?