1

My approval process has this criteria: Account: Account Name NOT EQUAL TO erwerwerwf and I have no issue putting an account into approval through Salesforce

yet when I run this code through anon Apex I get an error:

    Account a = new Account(Name='abcdefg');
    insert a;
    User user1 = [SELECT Id FROM User][0];
    Approval.ProcessSubmitRequest req1 = 
        new Approval.ProcessSubmitRequest();
    req1.setComments('Submitting request for approval.');
    req1.setObjectId(a.id);
    req1.setSubmitterId(user1.Id)
    Approval.ProcessResult result = Approval.process(req1);
    System.debug(result.getInstanceStatus() + ' - ' +result.getInstanceStatus());

this is the error

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

0

1 Answer 1

2

You are facing this error due to line no 3 there you are performing a query on the user. The result for same might fetch any user in the org and there are least chances it matches with your Initial Submitters that are defined in your approval process.

Resolutions:

  1. Query on a Specific user (that are initial submitters) by adding where clause.
  2. If the initial submitter is always record owner then set submitter like this req1.setSubmitterId(userinfo.getuserid());
1
  • If I remove that line about the submitter then it works Sep 5, 2017 at 14:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .