You need to sign in to do that
Don't have an account?
Ram 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();
}
}
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();
}
}
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: