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

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();
  insert l;
  // Create an approval request for the lead 
Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
req1.setComments('Submitting request for approval.');

// Submit the approval request for the lead 
Approval.ProcessResult result = Approval.process(req1); //This is where the error occurs

// Verify the result 

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.setNextApproverIds(new Id[] {UserInfo.getUserId()});

// Use the ID from the newly created item to specify the item to be worked 

// 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());