Following are the different ways to schedule a Schedule Job through a script. Run the given code in Execute Anonymous window and then you could see in Setting -> 'Scheduled Job' that your Job is waiting to be executed.
ScheduleSalesTargets c = new ScheduleSalesTargets();
c.execute(null);
Check the current Time. If it is, let's say 10:39 AM, in your clock, then set the minute to 41. This will schedule the job for 10:41 AM just two minutes from now. But, if you set minute value to 38, then it will schedule to next hour 11:38 AM
ScheduleSales c = new ScheduleSales();
String sch = '0 0 * * * ?';
System.schedule('Sales Job Name - 1', '0 41 * * * ?', c);
You could repeat following, so that job keeps running every 5 minutes while you debug and change the Apex code behind the scene.
ScheduleSales c = new ScheduleSales();
String sch = '0 0 * * * ?';
System.schedule('Sales Job Name - 1', '0 40 * * * ?', c);
System.schedule('Sales Job Name - 1', '0 45 * * * ?', c);
System.schedule('Sales Job Name - 1', '0 50 * * * ?', c);
System.schedule('Sales Job Name - 1', '0 55 * * * ?', c);
System.schedule('Sales Job Name - 1', '0 01 * * * ?', c);
global void execute(SchedulableContext SC) {
RecurringScheduleJob.startJob();
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() + 10);
String second = string.valueOf(system.now().second());
String year = string.valueOf(system.now().year());
String strJobName = 'Job-' + second + '_' + minute + '_' + hour + '_' + day + '_' + month + '_' + year;
String strSchedule = '0 ' + minute + ' ' + hour + ' ' + day + ' ' + month + ' ?' + ' ' + year;
System.schedule(strJobName, strSchedule, new scheduledTest());
}
}
Run a Schedule Job NOW
Method - 1
ScheduleSalesTargets c = new ScheduleSalesTargets();
c.execute(null);
Method - 2
(This one I prefer, whenever I need to run a job)Check the current Time. If it is, let's say 10:39 AM, in your clock, then set the minute to 41. This will schedule the job for 10:41 AM just two minutes from now. But, if you set minute value to 38, then it will schedule to next hour 11:38 AM
ScheduleSales c = new ScheduleSales();
String sch = '0 0 * * * ?';
System.schedule('Sales Job Name - 1', '0 41 * * * ?', c);
You could repeat following, so that job keeps running every 5 minutes while you debug and change the Apex code behind the scene.
ScheduleSales c = new ScheduleSales();
String sch = '0 0 * * * ?';
System.schedule('Sales Job Name - 1', '0 40 * * * ?', c);
System.schedule('Sales Job Name - 1', '0 45 * * * ?', c);
System.schedule('Sales Job Name - 1', '0 50 * * * ?', c);
System.schedule('Sales Job Name - 1', '0 55 * * * ?', c);
System.schedule('Sales Job Name - 1', '0 01 * * * ?', c);
Schedule a Job for every 10 Minutes
global class scheduledTest implements Schedulable{global void execute(SchedulableContext SC) {
RecurringScheduleJob.startJob();
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() + 10);
String second = string.valueOf(system.now().second());
String year = string.valueOf(system.now().year());
String strJobName = 'Job-' + second + '_' + minute + '_' + hour + '_' + day + '_' + month + '_' + year;
String strSchedule = '0 ' + minute + ' ' + hour + ' ' + day + ' ' + month + ' ?' + ' ' + year;
System.schedule(strJobName, strSchedule, new scheduledTest());
}
}
ReplyDeleteYou are posting a good information for people and keep maintain and give more updates too.
Salesforce Training | Online Course | Certification in chennai | Salesforce Training | Online Course | Certification in bangalore | Salesforce Training | Online Course | Certification in hyderabad | Salesforce Training | Online Course | Certification in pune
nice post.salesforce training
ReplyDeletesalesforce online training
salesforce online course
Yeni perde modelleri
ReplyDeleteSMS ONAY
VODAFONE MOBİL ÖDEME BOZDURMA
Nft Nasıl Alınır
ANKARA EVDEN EVE NAKLİYAT
trafik sigortası
Dedektör
kurma.website
Ask kitaplari
smm panel
ReplyDeleteSmm Panel
is ilanlari blog
İnstagram Takipçi Satın Al
Hirdavatciburada.com
beyazesyateknikservisi.com.tr
SERVİS
Tiktok hile indir
en son çıkan perde modelleri
ReplyDeleteyurtdışı kargo
en son çıkan perde modelleri
özel ambulans
nft nasıl alınır
minecraft premium
uc satın al
lisans satın al
Congratulations on your article, it was very helpful and successful. 97132263702e1dcd1844f09770d86a9a
ReplyDeletesms onay
website kurma
numara onay
Thank you for your explanation, very good content. a8cc7badd119917de13d0bd03226c9f6
ReplyDeletealtın dedektörü
Good content. You write beautiful things.
ReplyDeletesportsbet
mrbahis
vbet
vbet
hacklink
sportsbet
korsan taksi
hacklink
mrbahis
dijital kartvizit
ReplyDeletereferans kimliği nedir
binance referans kodu
referans kimliği nedir
bitcoin nasıl alınır
resimli magnet
FB8İ1
hatay
ReplyDeletekars
mardin
samsun
urfa
OMS
Get blazing fast Dedicated Server in Dallas for unbeatable performance. Reliable server solutions tailored to your needs. Explore options now!
ReplyDelete