+ Start a Discussion
Pavan AnnaldasPavan Annaldas 

Errors in Batch Apex Test Class Code.

I am trying to run my test and I keep getting this error message:

Failure Message:  "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.", Failure Stack Trace:
"External entry point"


But its giving 100% code coverage.

Thanks!

@isTest
public class TestBatchClass{
     static testmethod void BatchMethod(){
    try{
         List<case> csLst = new List<case>();
         Case cs;
         for (Integer i=0;i<10;i++) {
            cs = new case();
            cs.FirstName__c = 'abc'+i;
            cs.MiddleName__c = 'z1';
            cs.Lastname__c = 'TestCase123'+ i;
            cs.Status = 'New';
            cs.Company__c = 'Accenture1';
            cs.AssistantEmail__c = 'acc@gmail.com';
            cs.AssistantPhone__c = '123456'+i;
            cs.PrimaryNationality__c = 'India';
            cs.Birthdate__c = system.today();
            cs.PersonalEmail__c = 'acc1@gmail.com';
            cs.OtherEmail__c = 'acc2@gmail.com';
            cs.WorkEmail__c = 'acc3@gmail.com';
            cs.WorkPhone__c = '1234568'+i;
            cs.WorkMobile__c = '123456123'+i;
            cs.Mobile__c = '1234560000'+i;
            cs.HomePhone__c = '123456111'+i;
            cs.EventUniqueId__c = '123';
            cs.CampaignUniqueID__c = '456';  
            CS.IsProcessed__c = false ;
            csLst.add(cs);
           }
           insert csLst;
          Test.startTest(); 
          system.debug('*********insert************' +csLst);
          Batch_Case bc= new Batch_Case();                    /// Batch class name "Batch_Case"
          ID batchprocessid = Database.executeBatch(bc);
          //system.debug('****batchprocessid***'+batchprocessid);
          Test.stopTest();
    }
    catch(Exception e){
    }    
  }
}
kiranmutturukiranmutturu
Can you check the size of the records that you are getting in this test execution transaction.. The error seems to be like you are getting more than 200 records in the test context which is wrong . Check the class API version also?