please give me the example program of apex schedular job.How to run the developer console that code give one example. please Give some ideas.
6 Answers
I assume you have a Schedulable class created? You can schedule it using the system.schedule command:
system.schedule('Name of Job', '0 0 * * * ?', new MySchedulableClass());
Where '0 0 * * * ?' is a CRON expression to run the job every hour.
More details here: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_scheduler.htm
This simple script should be all you need if you want to test your class in the dev console.
scheduledClassExample abc = new scheduledClassExample();
abc.execute(null);
-
The execute method of a class that implements Schedulable interface can not be execute by a user. System.schedule(jobName, cronExpression, schedulableClass) should be used. Commented Jul 8, 2016 at 17:07
-
@DenisPereverzev I have used that script in the dev console execution window for months and it works just fine. Commented Jul 8, 2016 at 17:56
-
I can confirm this worked for me as well, from an admin account.– Link14Commented May 9, 2023 at 16:21
Something like this
String CRON_EXP = '0 30 * * * ?';
SWD_SoftwareDownloadScheduler sch = new SWD_SoftwareDownloadScheduler();
system.schedule('SWD_SoftwareDownloadScheduler - Hourly (TEST)', CRON_EXP, sch);
This runs hourly 30 minutes past the hour.
Link for generating CRON expressions - http://www.cronmaker.com/
-
give one example for Schedule an Apex class every 10 minutes Commented Jul 7, 2015 at 8:49
-
can you give example of Schedule an Apex class and howto run it Commented Jul 7, 2015 at 9:23
-
-
Replace this SWD_SoftwareDownloadScheduler with your own class name too Commented Jul 7, 2015 at 10:49
try this:
apexScheduledJob myJob = new apexScheduledJob ();
String sch = '0 0 0,2,4,6,8,10,12,14,16,18,20,22 ? * *';
System.schedule('My Job', sch, myJob);
We can use Cron expression to run scheduled job-in-developer-console. Referal link:- http://docs.oracle.com/cd/E12058_01/doc/doc.1014/e12030/cron_expressions.htm
Datetime dt = Datetime.now().addMinutes(1);
String CRON_EXP = '0 '+ dt.minute() + ' * ' + dt.day() + ' ' + dt.month() + ' ? ' + dt.year();
ScheduleBatch.SchedulerMethod('Sample_Heading', CRON_EXP, new ScheduleBatch () );
Run a Schedule Job NOW
ScheduleSalesTargets c = new ScheduleSalesTargets();
c.execute(null);
OR
Check the Time Now, 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
ScheduleSalesTargets c = new ScheduleSalesTargets();
String sch = '0 0 * * * ?';
System.schedule('Sales Target Job11', '0 41 * * * ?', c);