Batch 类 Apex 中的执行混淆 [英] Execution Confusion in Batch class Apex

查看:26
本文介绍了Batch 类 Apex 中的执行混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am calling a batch class instance and after completing the batch, I am calling two other batch class instances. The finish() method for first batch class is

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 将被调用两次,但它只被调用一次.循环运行了两次(我分析了调试日志).为什么只调用一次?

The problem I am facing is I am expecting that Batch class BatchPublicCampaignsToGoogle will be called two times but it is called only one time. The loop is running for two times (I analysed debug log). Why it is called only one time?

推荐答案

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

Chaining Batch Jobs was introduced as a feature in Winter 13. From the release notes:

您现在可以开始批处理通过从另一个批处理作业调用 Database.executeBatch批处理类的finish 方法.这允许您链接您的批次就业并创造就业链.请注意,州长限制批处理作业仍然适用.此更改适用于使用以下方式保存的批处理 ApexSalesforce.com API 版本 26.0 及更高版本.以前,Apex 已保存使用 Salesforce.com API 版本 25.0 及更早版本,您无法调用Database.executeBatch 来自任何批处理 Apex 方法.版本used 是正在运行的批处理类的版本,它启动另一个批处理作业.如果正在运行的批处理类中的 finish 方法调用了一个帮助程序类中的方法来启动批处理作业,Salesforce.com辅助类的 API 版本无关紧要.来源

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 类,您可以将一个批处理作业链接到刚刚完成的作业的末尾.当一个作业完成时,您不能分支并启动多个批处理作业.

So for Apex classes using API version 26.0 and later you can chain one batch job onto the end of one that just finished. You can't branch out and start multiple batch jobs when one finishes.

这篇关于Batch 类 Apex 中的执行混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆