4

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?

  • Is the approval process configured the same way in the second sandbox? – Mike Chale May 30 '13 at 18:57
  • Yes, I've checked this quite a few times now. I should also add that as System Admin I can trigger the Approval Process in both environment by editing and saving the Opportunity.Stage to 'Closed Won' – cyorkston May 30 '13 at 19:03
  • I don't understand your comment armadilo :) You're saying that you can kick off the process through edit->trigger but the question says it fails. For you? For another user? If both sandboxes are on Summer'13 you can fetch approval-related metadata to Eclipse and run file comparison (WinMerge?) to be 100% sure they're the same... If it's really "works for me but not for another user" then maybe approval somehow mentions Manager field or some queue membership? Plus - as stupid as it sounds - is the process activated :) – eyescream May 30 '13 at 19:58
  • 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. – cyorkston May 30 '13 at 21:04
  • 2
    @armadillo When you get the chance can you add that as an actual answer as opposed to a comment? Could be of used to others! – Matt Lacey May 30 '13 at 21:20
5

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.