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
VSK98VSK98 

Is it possible to run the schedule class for every second................

Hi All,

Is it possible to run the scheduler class every one minute.............Because my req comes like only


Notifications need to send every 1 hr,2 hrs , 3 hr & 4 hrs
The record might be created at every minute in a hour.....
 
Best Answer chosen by VSK98
JyothsnaJyothsna (Salesforce Developers) 
Hi ,

Please try the below sample code in the anonymous block.
 
Datetime sysTime = System.now().addSeconds( 1 );      
   String chronExpression = '' + sysTime.second() + ' ' + sysTime.minute() + ' ' + sysTime.hour() + ' ' + sysTime.day() + ' ' + sysTime.month() + ' ? ' + sysTime.year();
 System.schedule( 'SelfSchedule11 ' + sysTime, chronExpression, new scheduleClass1() );

Hope this helps you!
Best Regards,
Jyothsna

All Answers

pconpcon
The most granular you can get realistically get is down to the minute.  There are some limitations around this, because you'll quickly hit your 250,000 exectutions / 24hrs.  The theoritical max is running every 2.8s.  Also, this is not a guarenteed run time, but is instead when it will be scheduled to run.  This can take time to both start running and the complete running.
JyothsnaJyothsna (Salesforce Developers) 
Hi ,

Please try the below sample code in the anonymous block.
 
Datetime sysTime = System.now().addSeconds( 1 );      
   String chronExpression = '' + sysTime.second() + ' ' + sysTime.minute() + ' ' + sysTime.hour() + ' ' + sysTime.day() + ' ' + sysTime.month() + ' ? ' + sysTime.year();
 System.schedule( 'SelfSchedule11 ' + sysTime, chronExpression, new scheduleClass1() );

Hope this helps you!
Best Regards,
Jyothsna
This was selected as the best answer
AmitSahuAmitSahu
Why you want in batch . Can you not use time bases workflows ?