I am trying to set up a test class to test a Visualforce page button which, when clicked, submits a custom object record to an approval process using a controller method. When I try the test below, I get an error:
System.DmlException: Process failed. First exception on row 0; first error: NO_APPLICABLE_PROCESS, No applicable approval process was found.:
My only entry criteria is that the Region on the Opportunity starts with "NA", which is does, adn the approval process is active. Does anyone have any idea why I get this error?
Class for Creating Account and Opp Records:
public class TestCreateRecords {
// create and insert a new Account record.
public static Account createAcct(Integer i){
Account acct = new Account();
acct.Name = 'Test' + i;
acct.Language__c = 'English';
acct.Industry = 'Automotive';
acct.CurrencyIsoCode = 'USD';
acct.Region__c = 'NA-US-NE';
acct.BillingCity = 'New York';
acct.BillingState = 'New York';
acct.BillingCountry = 'United States';
return acct;
}
public static Opportunity createOppNew (Id acctId){
Opportunity opp2 = new Opportunity();
opp2.AccountId = acctId;
opp2.Name = 'Test Opportunity - ';
opp2.StageName = System.Label.Eng_OppStage3;
opp2.CloseDate = date.newinstance(2020,1,31);
opp2.Amount = 1000;
opp2.Region__c = 'NA-US-NE';
return opp2;
}
}
Test Class:
@Istest (SeeAllData=true)
private class TestControllerDealSumm
{
Account acct3 = TestCreateRecords.createAcct(0);
insert acct3;
Opportunity opp3 = TestCreateRecords.createOppNew(acct3.Id);
insert opp3;
Summary__c DS3 = new Summary__c();
DS3.Opportunity__c = opp3.Id;
DS3.Agreement_Effective_Date__c = date.newinstance(2025,1,31);
DS3.Net_Payment_Term_Days__c = 60;
DS3.Auto_Renewal__c = TRUE;
Insert DS3;
ApexPages.StandardController Summ1a = new ApexPages.standardController(opp3);
VF_SummaryController SummCont1a = new VF_SummaryController(Summ1a);
SummCont1a.DS.add(DS3);
SummCont1a.Summary();
SummCont1a.save();
ApexPages.StandardController Summ3 = new ApexPages.standardController(DS3);
DSReviewController SummCont3 = new DSReviewController(Summ3);
SummCont3.myDS = DS3;
SummCont3.approve();
// Create an approval request for the account
Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
req1.setComments('Submitting request for approval.');
req1.setObjectId(acct3.Id);
// Submit the approval request for the account
Approval.ProcessResult result = Approval.Process(req1);
// Verify the result
System.assert(result.isSuccess());
System.assertEquals(
'Pending', result.getInstanceStatus(),
'Instance Status'+result.getInstanceStatus());
}
Controller:
public class DSReviewController {
public Summary__c myDS;
public DSReviewController(ApexPages.StandardController stdController){
this.myDS = (Summary__c)stdController.getRecord();
}
public pageReference approve() {
Approval.ProcessSubmitRequest approve1 = new Approval.ProcessSubmitRequest();
approve1.setComments('Submitting request for approval.');
approve1.setObjectId(myDS.id);
approve1.setProcessDefinitionNameOrId(null);
approve1.setSkipEntryCriteria(true);
Approval.ProcessResult result = Approval.process(approve1);
PageReference RetPage = ApexPages.currentPage();
RetPage.setRedirect(true);
return RetPage;
}
}
seeAlldata=true
shouldn't be needed hereUtil.mockEnv()
method that every testmethod calls