4
// Insert an account

Account a = new Account(Name='Test',
                     annualRevenue=100.0);

insert a;

// Create an approval request for the account
Approval.ProcessSubmitRequest req1 = 
      new Approval.ProcessSubmitRequest();
req1.setObjectId(a.id);
req1.setNextApproverIds(new Id[] {'***************'});
// Submit the approval request for the account
Approval.ProcessResult result = 
                   Approval.process(req1);

Am trying to execute this code in anonymous block. How ever when tried in trigger i got same error all the time. Hard coded next approvers ID. No luck.

Any suggestions on what am I doing wrong ? Please help!!

  • 1
    I have one more doubt on this. to execute this or run approval via Apex should i have a approval process defined on Account in prior ? because once i define a approval process this error disappears. – Soberano Sep 4 '13 at 12:32
  • 1
    Yes, the approval process must exist in your system. Check out my answer for more details. – Jesse Altman Sep 4 '13 at 13:34
5

Is there a chance you created the approval process but don't have it activated? Does your account meet the entry criteria for your approval process? This error is thrown when an object is attempted to be submitted for approval and no approval process can be found, either because it isn't activated or your object doesn't meet the entry criteria.

You can not just instantiate this code. There must already be an approval process in the system for you to be able to run this code.

  • I was actually trying to have an approval process with more than 15 steps. I got to know what exactly error meant . And also now I am able to chain the Approval processes and get away with the limitation of 15 steps. Thank you people . thank you @Jesse Altman. – Soberano Sep 4 '13 at 14:34
4

I think there is a problem with profile permissions. Try with this code:

Account acc1 = new Account(Name='acc1');
        insert acc1

        if([select count() from ProcessInstance where targetobjectid=:acc1.id] < 1)
        {       
            Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
            req.setComments('Approve.');
            req.setNextApproverIds(new Id[] {UserInfo.getUserId()});
            req.setObjectId(acc1.Id);

            //Submit the approval request
            Approval.ProcessResult result = Approval.process(req);

        }
  • No luck. And also i am the system admin and have "Modify all data " permission. Am wondering what is the meaning of error and why is it throwing the error on Approval.process(); line. – Soberano Sep 4 '13 at 11:18

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.