Salesforce 定期执行Apex代码或根据时间触发?

Salesforce 定期执行Apex代码或根据时间触发?,salesforce,apex-code,Salesforce,Apex Code,我正在构建一个时间记录应用程序,记录用户在项目中花费的时间 不,我们必须开发一个功能来检查某个人是否正在接近某个特定项目的最长时间,以便Salesforce可以通知项目经理 起初我想从外部信息集中这些信息,但是。。。如果有办法在salesforce中每小时执行一项特定任务,那么这可能是最好的解决方案 有什么办法吗?你要找的是你要找的是是的,scheduled Apex就是你要找的工具。下面是一些示例代码,可以帮助您开始: global with sharing class YourSchedul

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

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

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


有什么办法吗?

你要找的是

你要找的是

是的,scheduled 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();
    }
}

是的,scheduled 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();
    }
}