0

I have a approval process set up already. when an agent submits records for approval, their status will be "Approval pending" and waits for Manager" i m trying to update their status as "approved" from list view. Accounts--> accounts listview-->select records-->click on 'approve records'--> shoud be approved.

the error. - Error:Cannot submit object already in process. How to avoid this?

I the controller i'm invoking Approval Process as below.

if(recs!=null && recs.size()>0){
    for(Lead ld : records){
        Approval.ProcessSubmitRequest AP1 = new Approval.ProcessSubmitRequest();
        AP1.setObjectId(ld.id);
        Approval.ProcessResult result = Approval.process(AP1);
    }
}
update recs;
  • I'm not sure you can do this - once a record goes into an approval process, it becomes locked. It can't go back into the same approval process until after it comes out via final approval/final rejection. Approval process field updates are used to update the 'status' as the record moves through the approval steps. These field updates can cause triggers to execute for additional processing – cropredy Nov 4 '14 at 22:42
0

I was able to figure this out. From the code i posted, i was resubmitting the record. Approval.ProcessSubmitRequest AP1 = new Approval.ProcessSubmitRequest();

By adding the line as below, i was able to get the workitem that i needed, refer the document for more information. (https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_ProcessWorkitemRequest.htm).

Approval.ProcessWorkitemRequest req2 = new Approval.ProcessWorkitemRequest();

  • Please mark this as the answer so it does not keep getting bumped by the automated processes.. – Eric Nov 11 '14 at 5:03

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.