You need to sign in to do that
Don't have an account?
Sunny S
Test Class Error Help!!
Hello dear community!!
Hoping somebody could help me with the below Test Class error.
I have a @isTest class which is failing the 'Run Test' throwing the following error message: '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.'
Apparently the Code Coverage is coming as 100%
I've referenced the following Salesforce article : https://help.salesforce.com/s/articleView?id=000330685&type=1
Test Class Code:
@isTest private class MilestoneTest { static testMethod void TestCompleteMilestoneCase(){ Set<String> milestoneNames = new Set<String>{'Resolution Time','Waiting for Customer','Change of Status'}; List<Account> acts = new List<Account>(); Account myAcc = new Account(Name='TestAct', phone='1001231234'); acts.add(myAcc); Account busAcc = new Account(Name = 'TestForMS', phone='4567890999'); acts.add(busAcc); insert acts; Contact cont = new Contact(FirstName = 'Test', LastName = 'LastName', phone='4567890999', accountid = busAcc.id); insert(cont); Id contactId = cont.Id; Entitlement entl = new Entitlement(); List<SlaProcess> lstEntitlementProcess = [SELECT Id, Name FROM SlaProcess WHERE IsActive = true limit 1]; if (lstEntitlementProcess.size()>0){ entl = new Entitlement(Name='Customer Feedback SLA',SlaProcessId= lstEntitlementProcess[0].id,AccountId=busAcc.Id,type='Change of Status', StartDate=Date.valueof(System.now().addDays(-2)), EndDate=Date.valueof(System.now().addYears(2))); insert entl; } String entlId; if (entl != null) entlId = entl.Id; List<Case> cases = new List<Case>{}; if (entlId != null){ Case c = new Case(Subject = 'Test Case with Entitlement ', Priority='High', EntitlementId = entlId, ContactId = contactId,slaStartDate=system.now()); cases.add(c); } if(cases.isEmpty()==false){ insert cases; List<Id> caseIds = new List<Id>(); for (Case cL : cases){ caseIds.add(cL.Id); } Test.startTest(); milestoneUtils.completeMilestone(caseIds, milestoneNames, System.now()); Test.stopTest(); } } }
*******#####*********
FYI - There is a Batch Class in the system which is running for a different installed Application.
Help: Could somebody suggest me the changes that I should be making to this Test Class in order to make it run successfully ?
Thanks in advance!!
Hoping somebody could help me with the below Test Class error.
I have a @isTest class which is failing the 'Run Test' throwing the following error message: '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.'
Apparently the Code Coverage is coming as 100%
I've referenced the following Salesforce article : https://help.salesforce.com/s/articleView?id=000330685&type=1
Test Class Code:
@isTest private class MilestoneTest { static testMethod void TestCompleteMilestoneCase(){ Set<String> milestoneNames = new Set<String>{'Resolution Time','Waiting for Customer','Change of Status'}; List<Account> acts = new List<Account>(); Account myAcc = new Account(Name='TestAct', phone='1001231234'); acts.add(myAcc); Account busAcc = new Account(Name = 'TestForMS', phone='4567890999'); acts.add(busAcc); insert acts; Contact cont = new Contact(FirstName = 'Test', LastName = 'LastName', phone='4567890999', accountid = busAcc.id); insert(cont); Id contactId = cont.Id; Entitlement entl = new Entitlement(); List<SlaProcess> lstEntitlementProcess = [SELECT Id, Name FROM SlaProcess WHERE IsActive = true limit 1]; if (lstEntitlementProcess.size()>0){ entl = new Entitlement(Name='Customer Feedback SLA',SlaProcessId= lstEntitlementProcess[0].id,AccountId=busAcc.Id,type='Change of Status', StartDate=Date.valueof(System.now().addDays(-2)), EndDate=Date.valueof(System.now().addYears(2))); insert entl; } String entlId; if (entl != null) entlId = entl.Id; List<Case> cases = new List<Case>{}; if (entlId != null){ Case c = new Case(Subject = 'Test Case with Entitlement ', Priority='High', EntitlementId = entlId, ContactId = contactId,slaStartDate=system.now()); cases.add(c); } if(cases.isEmpty()==false){ insert cases; List<Id> caseIds = new List<Id>(); for (Case cL : cases){ caseIds.add(cL.Id); } Test.startTest(); milestoneUtils.completeMilestone(caseIds, milestoneNames, System.now()); Test.stopTest(); } } }
*******#####*********
FYI - There is a Batch Class in the system which is running for a different installed Application.
Help: Could somebody suggest me the changes that I should be making to this Test Class in order to make it run successfully ?
Thanks in advance!!
Refer the help article to fix the issue.
https://help.salesforce.com/s/articleView?id=000330685&type=1
check this also.
https://www.infallibletechie.com/2015/11/systemunexpectedexception-no-more-than.html#:~:text=If%20you%20face%20%E2%80%9CSystem.,not%20called%20more%20than%20once.
If this information helps, Please mark it as best answer.
Thanks!!
I've already reffered the suggested links and unfortunately could not find a solution to my problem.
Could you suggest what line of the Test Class should I update to make it Run ?
Many Thanks!!
Thanks!!
MilestoneUtil Class:
try with below code.
If this helps, Please mark it as best answer.
Thanks!!
Thanks again Ankaiah.
Now getting the following Error 'Error: Compile Error: Variable does not exist: entlId at line 21 column 93' in line :
Case c = new Case(Subject = 'Test Case with Entitlement ', Priority='High',EntitlementId = entlId,
try with below code.
If this helps, Please mark it as best answer.
Thanks!!
Error message: Error: Compile Error: Variable does not exist: contactId at line 23 column 14
you need to assign the value for contactId = cont.id
If this helps, Please mark it as best answer.
Thanks!!
I am not able to save the Test Class but still getting the same Errror upon doing a Run Test.
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.
Not sure how do I overcome this error.
I am able to save the Test Class but still getting the same Errror upon doing a Run Test.
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.
Not sure how do I overcome this error.
Can you check that batch class, which objects records its processing?
refer the below link might help you to fix the issue.
https://salesforce.stackexchange.com/questions/174732/no-more-than-one-executebatch-can-be-called-from-within-a-test-method
Thanks!!