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
Ram ChaturvediRam Chaturvedi 

My schedule apex code is not working ,

I want to print some msg , 2 miniutes after scheduling ?

public class sceduleUpdate implements Schedulable{
    
public void UpdateStatus(){

   
  sceduleUpdate su = new sceduleUpdate();
   
  String day = string.valueOf(system.now().day());
             String month = string.valueOf(system.now().month());
         String hour = string.valueOf(system.now().hour());
         String minute = string.valueOf(system.now().minute() + 2);
         String second = string.valueOf(system.now().second());
         String year = string.valueOf(system.now().year());

 
  String JobName = 'Update';
         String strSchedule = second +' ' + minute + ' ' + hour + ' ' + day + ' ' + month + ' ?' + ' ' + year;
       
  string curMinute = string.valueOf(system.now().minute());
                System.debug('Job Schedule for Execution at '+hour+' :'+curMinute+' '+Minute);      



  System.schedule(JobName, strSchedule, su);
                System.debug('after schedule');
}

public void execute(SchedulableContext sc){
    
         String hour = string.valueOf(system.now().hour());
         String minute = string.valueOf(system.now().minute());
            system.debug('Hi code have been executed '+hour+' :'+minute+'');
   
       
    }


}
------------------------------------------------------------------
another class



@istest
public class callSchedule {
     public static testmethod void main(){
       
        sceduleUpdate Obj = new sceduleUpdate();
        obj.updateStatus();
 
     }
}
Avidev9Avidev9
Did you try to debug it ? Can you check the status of job Apex Job / Schedule Jobs ?
Ram ChaturvediRam Chaturvedi
I dont know how to check status , that's why i am trying to check in debug statement . 

Vadim RudkovVadim Rudkov
Actually, your class works. To verify that just execute in the Developer Console:

SceduleUpdate Obj = new SceduleUpdate();
obj.updateStatus();
Then, you can check out the log in the logs tab and monitor the status of the job: Setup -> Monitor -> Jobs -> Apex Jobs
But you can schedule your class only once. In order to schedule it again you have to delete the sheduled job first: Setup -> Monitor -> Jobs -> Scheduled Jobs

In test you don't need to schedule your class, just fix your test like:
@isTest
public class CallSchedule {
    public static testmethod void main(){

        SceduleUpdate obj = new SceduleUpdate();

        system.Test.startTest();
        obj.execute(null);
        system.Test.stopTest();

    }
}