Loading
Salesforce에서 이메일을 보내기 위해서는 도메인 인증이 필요합니다.더 많이 읽기

Salesforce Apex Error: 'No more than one executeBatch can be called from within a testmethod'

게시 일자: Sep 11, 2025
상세 설명

When processing more than 200 records in a test class for the batch apex class, you may see an error: System.UnexpectedException: No more than one executeBatch can be called from within a testMethod.

솔루션

In order to resolve the error, review the following:

 

  • Try to pass the less than 200 records in a test class.
  • Use Test.isRunningTest() to bypass the code starting the second job in this context. Meaning that you will have to test your second batch job in a separate test to get coverage and assert behavior. In doing so, you will have to reproduce manually in the test code, the state in the database that the second job expects. 

The following is an example of the change to avoid the second batch job being executed during test execution.

public void finish(Database.BatchableContext)
{
    if(!Test.isRunningTest)
         Database.executeBatch(new MySecondBatchJob));
}
Note
  • Enclose the executeBatch in Test.startTest() and Test.stopTest()
  • Always try to use @SeeAllData=false
Test.isRunningTest
Knowledge 기사 번호

000386014

 
로드 중
Salesforce Help | Article