You need to sign in to do that
Don't have an account?

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;
}
}
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;
}
}
A couple of things to note after looking at your test class:
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