gpt4 book ai didi

salesforce - Batch 类 Apex 中的执行混淆

转载 作者:行者123 更新时间:2023-12-04 05:05:16 25 4
gpt4 key购买 nike

我正在调用一个批处理类实例,在完成批处理后,我正在调用另外两个批处理类实例。第一个批处理类的 finish() 方法是

public void finish(Database.BatchableContext BC)
{
List<Event__c> events = [SELECT Id FROM Event__c];
delete events;

System.debug('Executing finish');
for (CalendarSettings__c c: [SELECT Id, Name, CalendarId__c,
CalendarQuery__c, FieldToDisplay__c
FROM CalendarSettings__c])
{
System.debug('Calendar Id is' + c.CalendarId__c);
BatchPublicCampaignsToGoogle bjob = new BatchPublicCampaignsToGoogle(
c.CalendarQuery__c, c.CalendarId__c, c.FieldToDisplay__c);
Database.executeBatch(bjob,9);
}

}

我面临的问题是我期待 Batch 类 BatchPublicCampaignsToGoogle将被调用两次,但只被调用一次。循环运行了两次(我分析了调试日志)。为什么只调用一次?

最佳答案

链接批处理作业是 Winter 13 中的一项功能。来自发行说明:

Starting a Batch Job from Another Batch Job

You can now start a batch job from another batch job by calling Database.executeBatch from the finish method of the batch class. This allows you to link your batch jobs and create a chain of jobs. Note that the governor limits of batch jobs still apply. This change applies to batch Apex saved using Salesforce.com API version 26.0 and later. Previously, with Apex saved using Salesforce.com API version 25.0 and earlier, you couldn’t call Database.executeBatch from within any batch Apex method. The version used is the version of the running batch class that starts another batch job. If the finish method in the running batch class calls a method in a helper class to start the batch job, the Salesforce.com API version of the helper class doesn't matter. Source



因此,对于使用 API 版本 26.0 及更高版本的 Apex 类,您可以链接 批处理作业拖到刚刚完成的作业的末尾。当一个作业完成时,您不能分支并启动多个批处理作业。

关于salesforce - Batch 类 Apex 中的执行混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15595406/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com