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
RahulRahul 

Hello friends, I have 85% code coverage, but still Iam not able to deploy my apex class. Need your help friends.Please find the code

Iam getting this error :-


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.
Stack Trace: External entry point

@isTest(seealldata = true)
public class QuoteTrigger_PayTerms_GenerateDoc_Test{
             
         Static testMethod Void testMethod2(){
           
             Account acc = new Account();
             acc.Name = 'Test Account';
             acc.Website ='www.test.com';
             acc.Type='Banking';
             insert acc;
             
             Contact con = new contact();
             con.lastname='test contact';
             con.LeadSource = 'Inbound';
             con.Contact_Status__c='Open';
             con.accountid=acc.id;
             insert con;
             
             opportunity opp = new opportunity();
             opp.name ='Test Opp';
             opp.stagename='Closed Won';
             opp.Type= 'New Business';
             opp.CloseDate=system.today().addmonths(2);
             opp.Upsell_Potential__c ='No';
             opp.RenewalDate__c = system.today();
             opp.accountid=acc.id;
             opp.Contact_Name__c=con.id;
             insert opp;  
             
             OpportunityContactRole ocr = new OpportunityContactRole();
                ocr.ContactId = con.Id;
                ocr.OpportunityId = opp.Id;
                ocr.IsPrimary = TRUE;
                ocr.Role = 'Decision Maker';
                insert ocr;
             
             SBQQ__Quote__c oldquote2 = new SBQQ__Quote__c();
             oldquote2.SBQQ__Primary__c = true;
             oldquote2.SBQQ__Opportunity2__c = opp.id;
             oldquote2.SBQQ__StartDate__c = system.today();
             oldquote2.SBQQ__EndDate__c= system.today().addmonths(3);
             oldquote2.SBQQ__SubscriptionTerm__c=1;
             oldquote2.Status_Of_Approval__c='Pending';
             oldquote2.Document_Template__c= 'Auto Renew 3';
             oldquote2.SBQQ__PaymentTerms__c= 'monthly';
             oldquote2.SBQQ__BillingCountry__c ='United States';
             oldquote2.Long_Form__c=false;
             oldquote2.Logo__c = false;
             oldquote2.Attach_Terms_and_Conditions__c= 'No';
             insert oldquote2;
   //--------------------------------------------------------------------------Annual Starts here----------------
             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'Annual';
             oldquote2.Logo__c = false;
             oldquote2.Attach_Terms_and_Conditions__c= 'Enterprise SaaS';
             update oldquote2;
             
             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'Annual';
             oldquote2.Logo__c = true;
             oldquote2.Attach_Terms_and_Conditions__c= 'Enterprise SaaS';      
             update oldquote2;   
             
             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'Monthly';
             oldquote2.Logo__c = false;
             oldquote2.Attach_Terms_and_Conditions__c= 'Enterprise SaaS';
             update oldquote2;
             
             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'Monthly';
             oldquote2.Logo__c = true;
             oldquote2.Attach_Terms_and_Conditions__c= 'Enterprise SaaS';      
             update oldquote2;   
         

         }
             
               
             Static testMethod Void testMethod3(){

//----------------------------------------------Standard saas------------------------------------------------
           

             Account acc = new Account();
             acc.Name = 'Test Account';
             acc.Website ='www.test.com';
             acc.Type='Banking';
             insert acc;
             
             Contact con = new contact();
             con.lastname='test contact';
             con.LeadSource = 'Inbound';
             con.Contact_Status__c='Open';
             con.accountid=acc.id;
             insert con;
             
             opportunity opp = new opportunity();
             opp.name ='Test Opp';
             opp.stagename='Closed Won';
             opp.Type= 'New Business';
             opp.CloseDate=system.today().addmonths(2);
             opp.Upsell_Potential__c ='No';
             opp.RenewalDate__c = system.today();
             opp.accountid=acc.id;
             opp.Contact_Name__c=con.id;

             insert opp;  
             
              OpportunityContactRole ocr = new OpportunityContactRole();
              ocr.ContactId = con.Id;
              ocr.OpportunityId = opp.Id;
              ocr.IsPrimary = TRUE;
              ocr.Role = 'Decision Maker';
              insert ocr;
             
             SBQQ__Quote__c oldquote2 = new SBQQ__Quote__c();
             oldquote2.SBQQ__Primary__c = true;
             oldquote2.SBQQ__Opportunity2__c = opp.id;
             oldquote2.SBQQ__StartDate__c = system.today();
             oldquote2.SBQQ__EndDate__c= system.today().addmonths(3);
             oldquote2.SBQQ__SubscriptionTerm__c=1;
             oldquote2.Status_Of_Approval__c='Pending';
             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'monthly';
             oldquote2.SBQQ__BillingCountry__c ='United States';
             oldquote2.Long_Form__c=false;
             oldquote2.Logo__c = false;
             oldquote2.Attach_Terms_and_Conditions__c= 'No';
             insert oldquote2;

             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'Annual';
             oldquote2.Logo__c = false;
             oldquote2.Attach_Terms_and_Conditions__c= 'Standard SaaS';
             update oldquote2;
             
             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'Annual';
             oldquote2.Logo__c = true;
             oldquote2.Attach_Terms_and_Conditions__c= 'Standard SaaS';      
             update oldquote2;   
             
             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'Monthly';
             oldquote2.Logo__c = false;
             oldquote2.Attach_Terms_and_Conditions__c= 'Standard SaaS';
             update oldquote2;
             
             oldquote2.Document_Template__c= 'Auto Renew';
             oldquote2.SBQQ__PaymentTerms__c= 'Monthly';
             oldquote2.Logo__c = true;
             oldquote2.Attach_Terms_and_Conditions__c= 'Standard SaaS';      
             update oldquote2;   
         

         }
            
    
        
    }
TechingCrewMattTechingCrewMatt
The error message indicates that the execute method of the batchable class is being executed more than once. The most likely cause is that the list returned from the start() method is larger than the scope indicated in th executeBatch() call. Please incude the functional code that is calling the batch and the batch able class itself.

A couple of things to note after looking at your test class:
  1. "seeAllData=true" should rarely be used. I have never needed to use it after I adopted that practice.
  2. A method annotated with @TestSetup should be used to insert the test records you'll need for all test methods that follow.
  3. A centralized factory class should be used to generate test data and return it to your test setup method. This makes adding newly required fields much easier.
  4. All test methods should include Test.startTest() and Test.stopTest() - especially if you are testing an asyncronous operation like a batchable class called by a trigger.
  5. Following the Test.stopTest() method call, assertions should be added to esure the data was processed correctly.
RahulRahul
Thanks for reply brother. I actually dont want to call a batch class. This test class is not for a batch class but  its for a normal class but I still  wonder how can it call a batch? Please help me not to call a batch
Andrew GAndrew G
@TechingCrewMatt 
I could not give a better answer - i think i might bookmark that one for future reference


@Rahul 
As alluded to by Matt, I would guess that one of your objects, most likely the quote object as it is the one being called again and again, is invoking a piece of batchable code.

Looking at what you are trying to test (it is nice that you are trying to get all permutatons ), I would do the TestSetup as mentioned by Matt and run 8 x methods doing each update / test individually.

Oh, and I would follow all of Matt's suggestions.

Regards
Andrew