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

Error in rescheduling already scheduled apex classes

Hi i m tryin to rescheduled already scheduled apex classes using system.schedule method.


When tryin to do this i m getting an error.


The following is my controller code


public with sharing class controller_dynamicScheduler {
    public String classNameToSchedule;
    public List<ApexClass> getschedulableClasses() {
        List<ApexClass> allClasses = [Select ApiVersion, Body, bodyCrc, IsValid, LengthWithoutComments, Name, NamespacePrefix, Status from ApexClass];
        List<ApexClass> schedulableClasses = new List<ApexClass>();
        for(ApexClass c : allClasses) {
            if(c.Body.containsIgnoreCase(ApexSchedulerSettings__c.getInstance('Scheduler').Schedule_Class_Keyword__c)) {
        return schedulableClasses;
    public PageReference scheduleNow() {
        System.debug('Class Name '+classNameToSchedule);
        String jobName = classNameToSchedule+' - ';
        String schTime ='ss mm HH dd MM ? yyyy');
        ApexClass class2Schedule = [Select Name from ApexClass Where Name=:classNameToSchedule];
         System.schedule(jobName, schTime, class2Schedule);
        return null;

 The following is my apex page code:


<apex:page controller="controller_dynamicScheduler">
<apex:form >
    <apex:pageMessages />
    <apex:pageBlock mode="edit" title="Schedulable Classes">
        <apex:pageBlockTable value="{!schedulableClasses}" var="apexClass">
            <apex:column value="{!apexClass.Name}"/>
            <apex:column value="{!apexClass.ApiVersion}"/>
            <apex:column >
                <apex:commandLink value="Schedule Now">
                    <apex:param name="className" assignTo="{!classNameToSchedule}" value="{!apexClass.Name}"/>

 i m getting the following error msg


Error: controller_dynamicScheduler Compile Error: You must select an Apex class that implements the Schedulable interface. at line 21 column 2






The last parameter you're passing to System.schedule has to be a new object. New instance of the class. What you're passing is the metadata information about the class, it's body etc... This stuff can't be "run" like that.


If you want to schedule multiple class together Check This Blog. Try System.schedule(jobName2, schTime, class2Schedule);
This should work . Let us know if you face problems .

Important :

Hit Kudos [Star Icon ] if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You