You need to sign in to do that
Don't have an account?
Approval Process TestMethod
I'm trying to write a testMethod for a lead approval process but despite my research and best efforts, I keep getting the error: System.DmlException: Process failed. First exception on row 0; first error: NO_APPLICABLE_PROCESS, No applicable approval process found.: []
Any recommendations? Below is the code.
static testMethod void test_LeadFunctionality_Tests(){
Lead l=new Lead();
l.lastname='Test';
l.Company='Test';
insert l;
// Create an approval request for the lead
Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
req1.setComments('Submitting request for approval.');
req1.setObjectId(l.id);
// Submit the approval request for the lead
Approval.ProcessResult result = Approval.process(req1); //This is where the error occurs
// Verify the result
System.assert(result.isSuccess());
System.assertEquals('Pending', result.getInstanceStatus(), 'Instance Status'+result.getInstanceStatus());
// Approve the submitted request
// First, get the ID of the newly created item
List<Id> newWorkItemIds = result.getNewWorkitemIds();
// Instantiate the new ProcessWorkitemRequest object and populate it
Approval.ProcessWorkitemRequest req2 = new Approval.ProcessWorkitemRequest();
req2.setComments('Approving request.');
req2.setAction('Reject');
req2.setNextApproverIds(new Id[] {UserInfo.getUserId()});
// Use the ID from the newly created item to specify the item to be worked
req2.setWorkitemId(newWorkItemIds.get(0));
// Submit the request for approval
Approval.ProcessResult result2 = Approval.process(req2);
// Verify the results
System.assert(result2.isSuccess(), 'Result Status:'+result2.isSuccess());
System.assertEquals('Approved', result2.getInstanceStatus(), 'Instance Status'+result2.getInstanceStatus());
}