1

Submitting an Opportunity into an approval when the Opportunity Stage is updated.

When setNextApproverIds is passed a List with a single ID in the list then the code works, when the list contains more than one ID then the following exception is thrown:

12:12:02.196 (6196664000)|EXCEPTION_THROWN|[454]|System.DmlException: Process failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, missing required field: [] 12:12:02.197 (6197779000)|USER_DEBUG|[459]|DEBUG|ERROR LOCKING OPPORTUNITY: System.DmlException: Process failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, missing required field: []

private static void submitAndApprovalRecord(Set<Id> recordIds) {
    /*
    will take an id and submit that record to an approval locking the record
    */
    try {
        List<Approval.ProcessSubmitRequest> submitApprovals = new List<Approval.ProcessSubmitRequest>();

        for (ID recordId:recordIds) {

            list<ID> approverIds = new List<ID>{Properties.OpportunityApprovalLockUserId};
            for(GroupMember gm : [select UserOrGroupId From GroupMember where Group.DeveloperName = Group Name']){
                approverIds.add(gm.UserOrGroupId);
            }
            system.debug('***approverIds: ' + approverIds);

            Approval.ProcessSubmitRequest submitApproval=new Approval.ProcessSubmitRequest();
            submitApproval.setObjectId(recordId);
            submitApproval.setComments('Submitted for approval. Please approve.');
            submitApproval.setNextApproverIds(approverIds);

            submitApprovals.add(submitApproval);

        }
        system.debug('submitApprovals...'+submitApprovals);


        // Submit the approval requests for the records 
        Approval.ProcessResult[] results=Approval.process(submitApprovals, true);
        for (Approval.ProcessResult result : results) {
            system.debug('result...'+result);
        }
    } catch (Exception ex) {
        system.debug('ERROR LOCKING OPPORTUNITY: ' + ex);
    }
    return;
}
  • 1
    I had seen that. The difference is that this is not unanimous, but first response. Any of the approvers should have the ability to approve. It did cross my mind that there is no option for this in apex. – andymahood__c Apr 11 '13 at 12:25
  • Can you modify your approval process to send it to a queue instead of "list of people"? Queue (even in approval marked as unanimous) will work on "first come first served". – eyescream Apr 11 '13 at 12:39
  • Is it possible that one of your approvers is also an opp owner? Also, what happens if you change the option on Approval.ProcessResult[] results=Approval.process(submitApprovals, true); to (submitApprovals, false) allowing partial success? – crmprogdev Apr 11 '13 at 14:25
1

REQUIRED_FIELD_MISSING error when Approval Process set to Manually Select Hi, This is may help you. I met this question same as your, and this is useful for me.

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.