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
Jay Parikh 36Jay Parikh 36 

Schedule job

I have schedule job which have to run every 20 min but when i am putting as a schedule job (from anno window )it only runs one time andafter that it is not working every 20 min it is only working when you submit once here is the code :


String str = system.now().addMinutes(20).format('ss mm HH dd MM ? yyyy'); 
System.schedule('WebcartPullProductsScheduled', str , new WebcartPullProductsScheduled());  

 
Akhil AnilAkhil Anil
Hi Jay,

You need to write it like this.
 
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() + 20);
String second = string.valueOf(system.now().second());
String year = string.valueOf(system.now().year());
String str = '0 ' + minute + ' ' + hour + ' ' + day + ' ' + month + ' ?' + ' ' + year;
System.schedule('WebcartPullProductsScheduled', str , new WebcartPullProductsScheduled());

This should work every 20 minutes. You need to invoke it only once.

Kindly mark as an answer so that we can close this thread if it works for you.