Newer Version Available
process()
Submits an array of approval process instances for approval, or processes an array of approval process instances to be approved, rejected, or removed. For more information, see “Set Up an Approval Process” in the Salesforce Help.
Syntax
1ProcessResult = connection.process( processType processRequest[])processType can be either ProcessSubmitRequest or ProcessWorkitemRequest
Usage
Use the process() call to perform either of the following two tasks:
- Submit an array of objects to the approval process. Objects cannot already be in an approval process when submitted. Use the ProcessSubmitRequest signature.
- Process an object that has been submitted to the approval process by performing an approval action (Approve or Reject). Use the ProcessWorkitemRequest signature.
Requests are processed and a ProcessResult is returned with the same process instances as sent in the request.
The failure of a particular record will not cause failure of the entire request.
Sample Code—Java
This sample accepts the ID of the sObject to process the approval for and an array containing the IDs of the next approvers. It creates a process approval request and submits it for approval. Finally, it parses the results of the process() call.
1public void processRecords(String id, String[] approverIds) {
2 ProcessSubmitRequest request = new ProcessSubmitRequest();
3 request.setComments("A comment about this approval.");
4 request.setObjectId(id);
5 request.setNextApproverIds(approverIds);
6 try {
7 ProcessResult[] processResults = connection
8 .process(new ProcessSubmitRequest[] { request });
9 for (ProcessResult processResult : processResults) {
10 if (processResult.isSuccess()) {
11 System.out.println("Approval submitted for: " + id + ":");
12 for (int i = 0; i < approverIds.length; i++) {
13 System.out
14 .println("\tBy: " + approverIds[i] + " successful.");
15 }
16 System.out.println("Process Instance Status: "
17 + processResult.getInstanceStatus());
18 } else {
19 System.out.println("Approval submitted for: " + id
20 + ", approverIds: " + approverIds.toString() + " FAILED.");
21 System.out.println("Error: "
22 + processResult.getErrors().toString());
23 }
24 }
25 } catch (ConnectionException ce) {
26 ce.printStackTrace();
27 }
28}Sample Code—C#
This sample accepts the ID of the sObject to process the approval for and an array containing the IDs of the next approvers. It creates a process approval request and submits it for approval. Finally, it parses the results of the process() call.
1public void processRecords(String id, String[] approverIds)
2{
3 ProcessSubmitRequest request = new ProcessSubmitRequest();
4 request.comments = "A comment about this approval.";
5 request.objectId = id;
6 request.nextApproverIds = approverIds;
7 try
8 {
9 ProcessResult[] processResults = binding.process(
10 new ProcessSubmitRequest[] { request });
11 foreach (ProcessResult processResult in processResults)
12 {
13 if (processResult.success)
14 {
15 Console.WriteLine("Approval submitted for: " + id + ":");
16 for (int i = 0; i < approverIds.Length; i++)
17 {
18 Console.WriteLine("\tBy: " + approverIds[i] + " successful.");
19 }
20 Console.WriteLine("Process Instance Status: "
21 + processResult.instanceStatus);
22 }
23 else
24 {
25 Console.WriteLine("Approval submitted for: " + id
26 + ", approverIds: " + approverIds.ToString() + " FAILED.");
27 Console.WriteLine("Error: "
28 + processResult.errors.ToString());
29 }
30 }
31 }
32 catch (SoapException e)
33 {
34 Console.WriteLine("An unexpected error has occurred: " +
35 e.Message + "\n" + e.StackTrace);
36 }
37}ProcessSubmitRequest Arguments
| Name | Type | Description |
|---|---|---|
| comments | string | Text that you want to accompany the submission. Don’t reference merge fields or formula
expressions. Submission comments appear in the approval history for the specified record. This text also appears in the initial approval request email if the template uses the {!ApprovalRequest.Comments} merge field. |
| nextApproverIds | ID[] | If the process requires specification of the next approval, the ID of the user to be assigned the next request. |
| objectId | ID | The record to submit for approval. |
| processDefinitionNameOrId | string | The unique name or ID of the specific approval process to which you want
the record to be submitted. The process must have the same object type as
the record you specified in objectId. Required if skipEntryCriteria is true. |
| skipEntryCriteria | boolean | If true, the record isn’t evaluated against the entry criteria set on the process that is defined in processDefinitionNameOrId. |
| submitterId | ID | The ID for the user who submitted the record for approval. The user
receives notifications about responses to the approval request. The user must be one of the allowed submitters for the process. |
ProcessWorkitemRequest Arguments
| Name | Type | Description |
|---|---|---|
| action | string | For processing an item after being submitted for approval, a string representing the kind of action to take: Approve, Reject, or Remove. Only system administrators can specify Remove. If the Allow submitters to recall approval requests option is selected for the approval process, the submitter can also specify Remove. |
| comments | string | Text that you want to accompany the submission. Don’t reference merge fields or formula
expressions. Submission comments appear in the approval history for the specified record. This text also appears in the initial approval request email if the template uses the {!ApprovalRequest.Comments} merge field. |
| nextApproverIds | ID[] | If the process requires specification of the next approval, the ID of the user to be assigned the next request. |
| workitemId | ID | The ID of the ProcessInstanceWorkitem that is being approved, rejected, or removed. |