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

System.Schedule To Run More Than One Hour From Now



I have a requirement in a test class to execute a System.Schedule for more than one hour past the current time.  I've tried the following but it's failing to run more than one hour from now. It's as if it runs within the current hour


String hourNow = ('' + System.Now()).substring(11,13);
Integer hourNowPlusTwo = Integer.valueof(hourNow) + 2;

         String scheduleTime = '1 1 ' + hourNowPlusTwo + ' * * ?';
          System.schedule('Run Cleanup', scheduleTime, CleanupCLass);


I'm new to Scheduling.  If I want to edit the above to 2 hours from now then if you know of the changes I need this would be appreciated.


Thanks in advance.

Best Answer chosen by Admin (Salesforce Developers) 
Try this
String scheduleTime = '0 00 '+(System.Now().hour()+2)' '+System.Now().day() +' '+System.Now().month()+' ?';

PS : just wrote this on notepad.