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 “Getting Started with Approval Processes” in the Salesforce online help.

Syntax

ProcessResult = connection.process( processType processRequest[])

processType can be either ProcessSubmitRequest or ProcessWorkitemRequest

Usage

Use the process() call to perform either of the following two tasks:

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.

Note

Because you can fire Apex triggers with this call, you may be updating fields that contain strings.

Starting with API version 15.0, if you specify a value for a field that contains a string, and the value is too big for the field, the call fails and an error is returned. In previous versions of the API the value was truncated and the call succeeded. If you wish to keep the old behavior with versions 15.0 and later, use the AllowFieldTruncationHeader SOAP header.

Sample Code—Java

public void processRecords(String id, String[] approverIds) {
  ProcessSubmitRequest request = new ProcessSubmitRequest();
  request.setComments("A comment about this approval.");
  request.setObjectId(id);
  request.setNextApproverIds(approverIds);
  try {
    ProcessResult[] processResults = 
        connection.process(new ProcessSubmitRequest[]{request});
    for (ProcessResult processResult : processResults) {
      if (processResult.isSuccess()) {
        System.out.println("Approval submitted for: " + 
            id + ":"
        );
        for (int i = 0; i < approverIds.length; i++) {
          System.out.println("\tBy: " + approverIds[i] + 
              " successful."
          );
        }
        System.out.println("Process Instance Status: " +
            processResult.getInstanceStatus());
      } else {
        System.out.println("Approval submitted for: " + id + 
            ", approverIds: " + approverIds.toString() + 
            " FAILED."
        );
        System.out.println("Error: " + 
            processResult.getErrors().toString());
      }
    }
  } catch (ConnectionException ce) {
    ce.printStackTrace();
  }
}

Sample Code—C#

private void doProcessSample(String id, String[] approverIds)
        {
    ProcessResult[] processResults;
    ProcessSubmitRequest request = new ProcessSubmitRequest();
    request.objectId = id;
 
    try
    {
        processResults = binding.process(new ProcessSubmitRequest[] { request });
        for (int i = 0; i < processResults.Length; i++)
        {
            ProcessResult processResult = processResults[i] 
    ;
            if (processResult.success)
    {
                Console.WriteLine("Approval submitted for:" + id + " successful.");
    }
    else
            {
                Console.WriteLine("Approval submitted for:" + id + " FAILED.");
                Console.WriteLine("Errors: " + processResult.errors.ToString());
            }
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.ToString());
    }
}

ProcessSubmitRequest Arguments

Name Type Description
objectId ID The object to submit for approval, for example, an Account, Contact, or custom object.
nextApproverIds ID[] If the process requires specification of the next approval, the ID of the user to be assigned the next request.
comment string The comment to add to the history step associated with this request.

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.
nextApproverIds ID[] If the process requires specification of the next approval, the ID of the user to be assigned the next request.
comment string The comment to add to the history step associated with this request.
workitemId ID The ID of the ProcessInstanceWorkitem that is being approved, rejected, or removed.

Response

ProcessResult[]

Faults

ALREADY_IN_PROCESS

NO_APPLICABLE_PROCESS

© Copyright 2000–2012 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.