4

I have an Approval Process that is programatically created. When the first (and only) approval step Assigned Approver is set to a specific user, or group of users, the process works fine.

However, when it is set to Manually Chosen, I get the following error (stack trace is below):

11:31:32.328 (328641000)|SYSTEM_METHOD_ENTRY|[1105]|Approval.process(Approval.ProcessRequest)
11:31:32.328 (328756000)|DML_BEGIN|[1105]|Op:Process|Type:ProcessRequest|Rows:1
11:31:32.345 (345163000)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:ApprovalProcessActions
11:31:32.359 (359885000)|WF_APPROVAL_SUBMIT|[Event: E-0009 a1dd00000009MU4]
11:31:32.392 (392425000)|WF_RULE_FILTER|[Event : Approval Status not equal to Approved]
11:31:32.392 (392452000)|WF_RULE_EVAL_VALUE|2
11:31:32.392 (392499000)|WF_EVAL_ENTRY_CRITERIA|Event Approval|00Xd0000001F2YW|true
11:31:32.404 (404806000)|WF_SPOOL_ACTION_BEGIN|Auto Evaluate
11:31:32.427 (427005000)|WF_PROCESS_NODE|Submit for Approval(Approval based on first response)
11:31:32.433 (433104000)|CODE_UNIT_FINISHED|Workflow:ApprovalProcessActions
11:31:32.434 (434736000)|DML_END|[1105]
11:31:32.434 (434856000)|EXCEPTION_THROWN|[1105]|System.DmlException: Process failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, missing required field: []

The code is straightforward:

Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
req1.setComments('Submitting request for approval.');
req1.setObjectId(currentEvent.id);
Approval.ProcessResult result = Approval.process(req1);

And the Approval Process is set up as follows:

enter image description here

I would like to know what the required field I'm missing is, and why it would work for a pre-assigned user but not allow manual selection.

1 Answer 1

8

When you have it set as Manually Chosen, you need to specify a next approver ID list using the setNextApproverIds(ID[]) method.

If the next step in your approval process is another Apex approval process, you specify exactly one user ID as the next approver. If not, you cannot specify a user ID and this method must be null.

I guess it isn't super clear, but essentially if you have it set as Manually Chosen you have to specify the approver.

5
  • 1
    Ah, ok. This begs the question though, how can it be manually chosen if the developer is the one who specifies it?
    – George S.
    Commented Oct 2, 2013 at 20:47
  • Well, if you aren't programmatically submitting it for approval and the user clicks the standard 'Submit for Approval' button, then they get prompted with a lookup to a User. When you submit it programmatically, obviously that won't happen. Commented Oct 2, 2013 at 22:12
  • Ah ok, so it's impossible to use Manually Chosen with programmatic approval processes. I assumed Salesforce would be smart enough to detect this and take the user to a standard interface.
    – George S.
    Commented Oct 3, 2013 at 3:07
  • Or at least I would need to create a user lookup in my VF page and pass it to the setNextApprovers method.
    – George S.
    Commented Oct 3, 2013 at 3:15
  • 2
    Exactly. It is not impossible, but you will need to provide your own mechanism for getting the Ids for the setNextApprovers method. Commented Oct 3, 2013 at 3:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .