[SalesForce] Error when automatically submitting an approval process using code in APEX class – NO_APPLICABLE_PROCESS, No applicable approval process found

I have a trigger which automatically starts an approval process if an Opportunity has its stage updated to 'Closed Won'.

if (o.StageName=='Closed Won') {
    Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
    req.setComments('Submitted for approval. Please approve.');
    req.setObjectId(o.Id);
    Approval.ProcessResult result = Approval.process(req);
}

The weird bit – this works fine in my dev environment, but throws the following errors in another sandbox:

System.DmlException: Process failed. First exception on row 0; first error: NO_APPLICABLE_PROCESS, No applicable approval process found

The IF statement correctly matches the entry criteria of the approval process. The error is highlight on this line: Approval.ProcessResult result = Approval.process(req);

Any ideas?

Best Answer

Solved.

Intial Submitters were set to Opportunity Owner.

The difference results experienced between environments was due to Profile differences. One User had Modify All permission on Opportunities and did not receive the error (obviously).

Removed 'Modify All' on Opportunities and added a public group to Intial Submitters.

Thanks for your help.

Related Topic