You need to sign in to do that
Don't have an account?

Error on Approval Process trigger
I have the below trigger in my Org. It automatically submits an approval to the manager when specific leads are marked as Lead Status - Disqualified.
trigger LeadSubmitApproval on Lead (after update) { ID RepID= [Select ID from Profile where Name = 'MINDBODY Sales Representative' Limit 1].id; ID SarahID= [Select ID from Profile where Name = 'International Associate Manager' Limit 1].id; for (Integer i = 0; i < Trigger.new.size(); i++) { if (Trigger.old[i].Status != 'Disqualified' && Trigger.new[i].Status == 'Disqualified' && (UserInfo.getProfileID() == RepID || UserInfo.getProfileId() == SarahID) && (Trigger.new[i].Lead_Type__c == 'Inbound' || Trigger.new[i].LeadSource == 'Trade Show')) { // create the new approval request to submit Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest(); req.setComments('Submitted DQ Lead for approval. Please approve.'); req.setObjectId(Trigger.new[i].Id); // submit the approval request for processing Approval.ProcessResult result = Approval.process(req); System.assert(result.isSuccess()); // display if the reqeust was successful System.debug('Submitted for approval successfully: '+result.isSuccess()); } } }
It has been working great for a few months, but has all of the sudden it is throwing the below error:
Apex script unhandled trigger exception by user/organization: 00560000001Np28/00D60000000J1xm
LeadSubmitApproval: execution of AfterUpdate
caused by: System.DmlException: Process failed. First exception on row 0; first error: ALREADY_IN_PROCESS, Cannot submit object already in process.: []
Trigger.LeadSubmitApproval: line 19, column 45
Can anyone help me understand why this all of the sudden started throwing errors ?? (Line 19, col 45 is highlighted in red above)
Next things to check:
1. Formula fields that may be updating the record or additional triggers that cause a recursive update thus causing the approval to be submitted twice.
All Answers
If nothing has changed in the trigger then:
Another process is submitting the record befor that specific trigger is ran. Did you copy the trigger, write a new one, etc...... Did you update the trigger with anything?
The error is basically telling you that the record has already been submitted and is awaiting approval or rejection.
That was my first hunch as well, but we have no other approval processes setup. In fact, if you go to the record itself, there are no approval processes assigned, nor is the record locked.
Without seeing full debug logs etc, it is hard to tell.
Below is the code for my approval process. You can add in the ID's etc where you need to. It is bulkified and check to see if the record is already in an active process....
See if it works for you..
I changed my Object to OBJECT and field that is checked to FIELD
Modify to suit your needs
I was actually looking at my debug logs and it appears it is submitting the request twice. If you have any ideas why this would be happening, I'd love to hear your input. I am looking into it separately tho.
Next things to check:
1. Formula fields that may be updating the record or additional triggers that cause a recursive update thus causing the approval to be submitted twice.
That was exactly it!!! I thought back about all the changes I had made and couldn't think of anything that overlapped with this error, but I guess I didn't think hard enough.
Thank you a lot!!!!