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
Alpesh Patel 16Alpesh Patel 16 

Getting error during to the deployment from stage to prodution

Hi,

I am trying to deploy my class and test case from stage to production. When I validate changeset on production, It throws following exception:
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.
Stack Trace: External entry point
.

Following is the code of my test case:

@isTest (SeeAllData=true)
public with sharing class SendWelcomeLetterCM_Test {
 
        
        List<Contract_User__c> contractUsers = new List<Contract_User__c>();
        List<Contract_Members__c> contractMembers = new List<Contract_Members__c>();
        
        //Create Account        
        Account testAccount = UnitTest.getAccount();
        insert testAccount;
        
        //Create Contacts
        Contact testContact= UnitTest.getContact(testAccount.Id);
        testContact.MailingCountry = 'CANADA';
        insert testContact;
        
        //Create Contacts
        Contact testContact1= UnitTest.getContact(testAccount.Id);
        testContact1.MailingCountry = 'CANADA';
        insert testContact1;
        
        //Create Contacts
        Contact testContact2= UnitTest.getContact(testAccount.Id);
        testContact2.MailingCountry = 'CANADA';
        insert testContact2;
        
        //create Learning
        Product2 testProductLRNABM = UnitTest.getProductLearning();
        testProductLRNABM.productcode = 'LRN-ABM';
        insert testProductLRNABM;  
        
        Product2 testProductTA3ABM = UnitTest.getProductAdvisoryTA3();
        testProductTA3ABM.productcode = 'TA3-ABM';
        insert testProductTA3ABM;
        
        //create team member
        Product2 testProductTA3DCS = UnitTest.getProductAdvisoryTA3();    
        testProductTA3DCS.Name = 'TA3-DCS';
        testProductTA3DCS.ProductCode = 'TA3-DCS';
        testProductTA3DCS.IsActive = true;
        insert testProductTA3DCS;
        
        //create team member
        Product2 testProductTA3CSS = UnitTest.getProductAdvisoryTA3();    
        testProductTA3CSS.Name = 'TA3-CSS';
        testProductTA3CSS.ProductCode = 'TA3-CSS';
        testProductTA3CSS.IsActive = true;
        insert testProductTA3CSS;
            
         // Create Contract
        Contract testContract = UnitTest.getContract(testAccount.Id);
        insert testContract;
        
         // create new Learning
        Contract_User__c testContractUserABM = UnitTest.getContractUser(testContract.Id, testContact.Id, testProductTA3ABM.Id);
        testContractUserABM.status__c = 'Active';
        insert testContractUserABM;
        
        //ContractUserRollup_New.rollupContractUsers(new List<Contract_User__c>{testContractUser}, null);
        
        Contract_User__c testContractUserDCS = UnitTest.getContractUser(testContract.Id, testContact1.Id, testProductTA3DCS.Id);
        testContractUserDCS.status__c = 'Active';
        insert testContractUserDCS;
        
        Contract_User__c testContractUserLRN = UnitTest.getContractUser(testContract.Id, testContact1.Id, testProductLRNABM.Id);
        testContractUserLRN.status__c = 'Active';
        insert testContractUserLRN;
        
        //ContractUserRollup_New.rollupContractUsers(new List<Contract_User__c>{ testContractUser1}, null);
        // create contract member
        Contract_Members__c testcontactmember = new Contract_Members__c();
        testcontactmember.Account__c = testAccount.Id;
        testcontactmember.Contact__c = testContact1.Id;
        testcontactmember.Contract__c = testContractUserABM.Contract__c;
        testcontactmember.Contract_User__c = testContractUserABM.Id;
        testcontactmember.Productlookup__c = testProductTA3ABM.id;
        testcontactmember.Status__c = 'Active';
        testcontactmember.Start_Date__c =system.today();
        testcontactmember.End_Date__c  = system.now().addDays(30).Date();
        insert testcontactmember;
        
         // create contract member
        Contract_Members__c testcontactmember1 = new Contract_Members__c();
        testcontactmember1.Account__c = testAccount.Id;
        testcontactmember1.Contact__c = testContact1.Id;
        testcontactmember1.Contract__c = testContractUserABM.Contract__c;
        testcontactmember1.Contract_User__c = testContractUserABM.Id;
        testcontactmember1.Productlookup__c = testProductTA3CSS.id;
        testcontactmember1.Status__c = 'Active';
        testcontactmember1.Start_Date__c =system.today();
        testcontactmember1.End_Date__c  = system.now().addDays(30).Date();
        insert testcontactmember1;

       //ContractMemberRollup_New.rollupContractMembers(new List<Contract_Members__c>{ testcontactmember}, null);    
        contractMembers.Add(testcontactmember);
        SendWelcomeLetterCM.onAfterInsert(contractMembers);
  }
}