You need to sign in to do that
Don't have an account?
Chamil Madusanka
Create an approval process in apex class
Hi All,
I want to create a approval process and assign some specific users to that approval process in apex class. I tried as follows;
Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
req1.setComments('Submitting request for approval.');
req1.setObjectId(newDPCD.id);
req1.setNextApproverIds(idList); //idList is a list of contact ids
But It didn't work. The main issue is I want to assign specific users dynamically.
Is there any work around? If someone have any idea or sample code please share it.
Thanks in Advance
Change your code to
let me know with your results
Hi,
Thank you for your reply shashikant. I tried that changes. But I got the following exception
System.DmlException: Process failed. First exception on row 0; first error: ALREADY_IN_PROCESS, Cannot submit object already in process. [] Trigger.approveTrainingRequest: line 92, column 54: []
This line 92 is at Approval.ProcessResult result = Approval.process(req1);
What is the issue? any solution?
Thanks in Advance
Once an Item is pending for approval then it can not be send to approval till it comes out of approval queue. You have to check whether an Item is in approval or not before sending it for approval.
How to create a IDlist?
I get this error :- Error: REQUIRED_FIELD_MISSING. The required field in the only active approval process is that of setting the next approver because the approval process has the condition of 'Let the submitter choose the approver manually.' So the approver set using setNextApproverIds is not being recognised. Any idea ?
instead of idList assign particular user id or user lookup field
example:
req1.setNextApproverIds('0000894059090');