Salesforce 一个testmethod内最多只能调用一个executeBatch
如何修复测试类中的以下错误消息Salesforce 一个testmethod内最多只能调用一个executeBatch,salesforce,apex,salesforce-lightning,Salesforce,Apex,Salesforce Lightning,如何修复测试类中的以下错误消息 System.UnexpectedException: No more than one executeBatch can be called from within a test method. Please make sure the iterable returned from your start method matches the batch size, resulting in one executeBatch invoca
System.UnexpectedException: No more than one executeBatch can be called from within a test method. Please make sure the iterable returned from your start method matches the batch size, resulting in one executeBatch invocation.
请注意,已尝试按此处建议添加限制200,但未成功
我的课程是
global class ERTExtract255BatchClass implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator(
'SELECT ID,Description,Case_Desc_255__c FROM Case'
);
}
global void execute(Database.BatchableContext bc, List<Case> scope){
// process each batch of record
List<Case> lstCase = new List<Case>();
for (Case cas : scope) {
string Strdesc = cas.Description ;
if(Strdesc.length()>255){
cas.Case_Desc_255__c = cas.Description.Left(255);
lstCase.add(cas);
}
}
update lstCase;
}
global void finish(Database.BatchableContext bc){
}
}
全局类ERTExtract255BatchClass实现数据库。可批处理{
global Database.QueryLocator启动(Database.BatchableContext bc){
return Database.getQueryLocator(
'从案例中选择ID、描述、案例描述\u 255\u c'
);
}
全局void execute(Database.BatchableContext bc,列表范围){
//处理每批记录
List lstCase=新列表();
对于(案例cas:范围){
字符串Strdesc=cas.Description;
如果(Strdesc.length()>255){
cas.Case_Desc_255__c=cas.Description.Left(255);
添加(cas);
}
}
更新案例;
}
全局void完成(Database.BatchableContext bc){
}
}
我的测试班是
@isTest(SeeAllData=false)
public class testERTExtract255BatchClass {
@IsTest
static void testBatchJob(){
List<Case> cases = new List<Case>();
for (integer i =0;i<300;i++)
{
Case c = new Case();
c.Description = 'aaaaaa'.rightPad(255,'b');
c.status = 'new';
c.Subject = 'test';
//add other mandatory fields
cases.add(c);
}
insert cases;
Test.startTest();
Database.executeBatch(new ERTExtract255BatchClass());
Test.stopTest();
Case Strcase = [Select id,Case_Desc_255__c from Case];
System.assertEquals(Strcase.Case_Desc_255__c.length(),255);
}
}
@isTest(参见AllData=false)
公共类测试员Extract255BatchClass{
@伊斯特
静态void testBatchJob(){
列表案例=新列表();
对于(整数i=0;i您需要for(整数i=0;i您需要for(整数i=0;i)的任何特殊原因