在apex salesforce中调试可调任务

时间:2022-09-12 11:20:58

i am trying to run a schedulable job i never used schedulable jobs in salesforce

我在尝试运行一个可调度的工作,我从来没有在salesforce使用可调度的工作

here is my code

这是我的代码

global class scheduledMerge implements Schedulable{
   global void execute(SchedulableContext SC) {
      System.debug('Hello World'); 
   }
}

          created a cusom controller
public class schedulableMerge{

public schedulableMerge(){

}
public PageReference Hello(){
scheduledMerge m = new scheduledMerge();
        String sch = '0 10 * * 1-12 ? *';
        system.schedule('Merge Job', sch, m);
        return null;
}

}

and visualforce page is

和visualforce页面

<apex:page controller="schedulableMerge">
  <!-- Begin Default Content REMOVE THIS -->
    <h1>Congratulations</h1>
  This is your new Page
  <!-- End Default Content REMOVE THIS -->
  <apex:form >
  <apex:commandButton value="Press it" action="{! Hello}" />
</apex:form>

</apex:page>

when i press button press it there is a job in All schedulable job but there is only one option delete with it.No option of manage. i think this job should run in every 10 minutes .i saw debug logs from Monitoring>Debug Log it is showing no log. can you please tell what is the expression for running job in every one minute and where to see debug logs?? my aim is to see working of schedulable job

当我按下按钮时,在所有可调度作业中都有一个作业,但是只有一个选项可以删除它。没有管理的选项。我认为这个工作应该每10分钟运行一次。我看到监控>调试日志的调试日志没有显示日志。请告诉我每一分钟运行作业的表达式是什么,在哪里可以看到调试日志?我的目标是看到可调度的工作。

3 个解决方案

#1


4  

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).

好消息-你不需要一个visualforce页面和控制器。坏消息——你不可能每隔一分钟就安排一次工作。我认为5分钟是最小值(但我不确定,你得尝试一下)。

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

如何按需运行(一次)?从开发人员控制台或Eclipse的“执行匿名”块。

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:

确保将用户添加到调试日志中,并强制执行作为界面一部分必须实现的execute方法:

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.

在完成一次运行后,用cron表达式进行实验。如果您对频率没有问题——您根本不需要这些表达式,请转到Setup -> Develop ->类并单击[Schedule Apex]。只有在每天需要多次运行时,才使用代码来调度类。

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)

最后但不是最不重要的-去安装和键入“Apex jobs”在搜索。您应该看到最近执行的所有异步任务的信息(计划作业、批处理、@future方法等)

#2


2  

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.

您可以尝试在当前运行的作业中安排新的作业(如果可能的话)来运行每个日期时间。now().minute() + 1。这个主意在我脑子里一闪而过。我没有试一试。同样的课程一分钟后开始。但是不要忘记在这个类中终止当前作业,这样就不会创建大量预定的作业,也不会超出调控器的限制。

#3


0  

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

我在预定的Apex中做了类似的事情,跑了15 30 45 60分钟(即每15分钟)

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

缺点是,我们需要为这个执行创建4个不同的预定的Apex作业。

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());

#1


4  

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).

好消息-你不需要一个visualforce页面和控制器。坏消息——你不可能每隔一分钟就安排一次工作。我认为5分钟是最小值(但我不确定,你得尝试一下)。

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

如何按需运行(一次)?从开发人员控制台或Eclipse的“执行匿名”块。

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:

确保将用户添加到调试日志中,并强制执行作为界面一部分必须实现的execute方法:

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.

在完成一次运行后,用cron表达式进行实验。如果您对频率没有问题——您根本不需要这些表达式,请转到Setup -> Develop ->类并单击[Schedule Apex]。只有在每天需要多次运行时,才使用代码来调度类。

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)

最后但不是最不重要的-去安装和键入“Apex jobs”在搜索。您应该看到最近执行的所有异步任务的信息(计划作业、批处理、@future方法等)

#2


2  

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.

您可以尝试在当前运行的作业中安排新的作业(如果可能的话)来运行每个日期时间。now().minute() + 1。这个主意在我脑子里一闪而过。我没有试一试。同样的课程一分钟后开始。但是不要忘记在这个类中终止当前作业,这样就不会创建大量预定的作业,也不会超出调控器的限制。

#3


0  

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

我在预定的Apex中做了类似的事情,跑了15 30 45 60分钟(即每15分钟)

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

缺点是,我们需要为这个执行创建4个不同的预定的Apex作业。

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());