function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion 

Batch Class Test Method Error

This is the code for test class of batch 


       LeadBatchAlertforIdleLead TA = new LeadBatchAlertforIdleLead();
       LeadBatchAlertforIdleLeadSchedule Sa =new LeadBatchAlertforIdleLeadSchedule();



Following is the error i am having while deploying it ...Code Coverage is although 80%






LeadBatchAlertforIdleLead_Test.myUnitTest System.UnexpectedException: No more than one executeBatch can be called from within a testmethod.  Please make sure the iterable returned from your start method matches the batch size, resulting in one executeBatch invocation.


It will be helpful if any body can provide me solution for setting the record limit  during test ,,, According to my search till now people are suggesting some query is returning more than 200 records.......


Error is focussed on my start method return query of Database.querylocator:


return Database.getquerylocator[  ma query];


My whole code is in start method of performing several tasks , no error with  that ....

Although some execution does goes in execute method





Well you cannot have more than one batches.
Make sure that while running test classes it doesnt pickup more than 200 records. [I am assuming that youare not depending on the org data for testing and youare creating your own records].

And change the code to take 200 records at a time


From test method never call two batch apexes as you are doing


LeadBatchAlertforIdleLead TA = new LeadBatchAlertforIdleLead();
LeadBatchAlertforIdleLeadSchedule Sa =new LeadBatchAlertforIdleLeadSchedule();

Use one so that it can take 200 records at a time.


If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.


Hey guys thanks for early response ......But I have something to share you ,if can spend some time on it ...




The above code i wrote for  test class  ,does not have two batches. The first class is batch instantiation and second is the scheduler instantiation.The line just excutes it, for it was an experiment for testing and it worked as before i forgot write the test class for the scheduler class , thats why got the error of two batch classes.Now its been successfully deployed and i also did SEEALLDATA=TRUE so also depended on org data.

(if any other complication that can arise in future pls ,recommend)