Debugging Schedulable Job in apex salesforce

老子叫甜甜 提交于 2019-12-06 08:08:55

Good news - you don't need a visualforce page and controller. Bad news - you can't schedule jobs with 1 minute intervals. I think 5 mins is the minimum (but I'm not sure, you'd have to experiment with it).

How to run it (once) on demand? From Developer Console or Eclipse's "Execute Anonymous" block.

Make sure your user is added to debug logs and simply force running of the execute method you had to implement as part of the interface:

scheduledMerge sm = new scheduledMerge();
sm.execute(null);

Experiment with the cron expressions after you're satisfied that one run completes succesfully. If you're fine with frequency once a day - you don't need these expressions at all, go to Setup -> Develop -> Classes and click [Schedule Apex]. Only if you need multiple runs a day use code to schedule the class.

Last but not least - go to setup and type "Apex jobs" in the search. You should see info of all asynchronous tasks performed recently (scheduled jobs, batches, @future methods etc)

can you please tell what is the expression for running job in every one minute and where to see debug logs??

You can't run it every minute. Minimum is ONE HOUR - Apex Scheduler. There is one huck - to run job as frequently as it possible to start a lot of jobs.

You can try to schedule new job in currently running job (if it's possible) to run every Datetime.now().minute() + 1. This idea just poped up in my mind. I didn't try it. So the same class will start in one minute. But don't forget to kill current job in this class so you don't create huge number of scheduled jobs and run out of governor limits.

I have done something like this for Scheduled Apex to run for 15,30,45,60 min (ie, every 15 mins)

The downside is, we need to create 4 different Scheduled Apex Jobs for this to execute.

System.schedule('Every 0th min', '0 0 * * * ?', new scheduledMerge());
System.schedule('Every 15th min', '0 15 * * * ?', new scheduledMerge());
System.schedule('Every 30th min', '0 30 * * * ?', new scheduledMerge());
System.schedule('Every 45th min', '0 45 * * * ?', new scheduledMerge());
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!