聚合查询不支持queryMore(),使用LIMIT将结果限制为单个批处理错误

时间:2014-09-16 23:41:15

标签: salesforce batch-processing apex soql

我正在使用如下的SOQL

select COUNT(Transaction_Type_Id__c) tt, Id__c from Analysis_set_header__c group by Id__c

该对象共有42条记录。但我收到错误

聚合查询不支持queryMore(),使用LIMIT将结果限制为单个批处理。

这是我的批次类

global class AnalysisSetWsCodeBatchClass implements Database.Batchable<sObject>,   Database.AllowsCallouts {

    public String query = 'select COUNT(Transaction_Type_Id__c) tt, Id__c from Analysis_set_header__c group by Id__c';
    global Database.QueryLocator start(Database.BatchableContext BC) {
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, AggregateResult[] groupedResults) { 
        set<String> setAh = new set<String>();

        for (AggregateResult ar : groupedResults)  {
            System.debug('--------header---' + ar.get('Id__c'));
            setAh.add((string) ar.get('Id__c'));
        }
        system.debug('----------------setAh----------------------'+setAh);
        if(!setAh.isEmpty()){
            AnalysisSetCodeWsUpdate aw = new AnalysisSetCodeWsUpdate();
            aw.updateAnalysisSetCode(setAh);
        }
    }

    global void finish(Database.BatchableContext BC){
       //you can also do some after-the-job-finishes work here  
    }

}

1 个答案:

答案 0 :(得分:0)

查询SELECT ID FROM Analysis_set_header__c时有多少条记录?超过43?我的建议是将您的SOQL字符串更改为以下内容:SELECT COUNT_DISTINCT(Transaction_Type_Id__c)tt,Id__c from Analysis_set_header__c order by COUNT_DISTINCT(Id__c)