【发布时间】:2020-07-25 16:17:44
【问题描述】:
如何在测试类中修复以下错误消息
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.
请注意,已经尝试按照此处https://help.salesforce.com/articleView?id=000330685&type=1&mode=1 的建议添加限制 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){
}
}
我的测试课是
@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);
}
}
【问题讨论】:
标签: salesforce apex salesforce-lightning