定期执行Apex代码还是依赖于时间触发?

时间:2012-10-08 11:43:44

标签: salesforce apex-code

我正在构建一个时间记录应用程序,用于记录用户在项目中花费的时间。

不,我们必须开发一项功能来检查某个人是否接近特定项目的最长时间,以便Salesforce可以通知项目经理。

起初我认为从外部信息中汇集这些信息但是......如果有一种方法可以在salesforce中每小时执行一项任务,那么这可能是最好的解决方案。

有什么办法吗?

2 个答案:

答案 0 :(得分:2)

您要找的是scheduled apex

答案 1 :(得分:2)

是的,预定的Apex是您正在寻找的工具。这里有一些示例代码可以帮助您入门:

global with sharing class YourScheduleClass implements Schedulable
{
    public static String CRON_EXP = '0 0 0-23 * * ?';

    global void execute(SchedulableContext ctx) 
    {
        // Usually best to call another class from here rather than implementing
        // logic directly in the schedule class
    }

    // Just to show how it's called...
    static testMethod void testExecute()
    {
        Test.startTest();
        String tmpId = System.schedule('ScheduleTest', YourScheduleClass.CRON_EXP, new YourScheduleClass());
        Test.stopTest();
    }
}