Search in sources :

Example 1 with ProcessWorkitemRequest

use of com.salesforce.soap.partner.ProcessWorkitemRequest in project tdi-studio-se by Talend.

the class PartnerSamples method processSample.

private void processSample() {
    // call the login function to do so
    if (!loggedIn) {
        if (!login()) {
            return;
        }
    }
    try {
        // First step is to create an account that matches the approval process criteria
        SObject acct = new SObject();
        acct.setType("Account");
        acct.set_any(new MessageElement[] { newMessageElement("Name", "API Approval Sample") });
        acct.setId(binding.create(new SObject[] { acct })[0].getId());
        // Next step is to submit the account for approval using a ProcessSubmitRequest
        ProcessSubmitRequest psr = new ProcessSubmitRequest();
        psr.setObjectId(acct.getId());
        psr.setComments("This approval request was initiated from the API.");
        ProcessResult p_res = binding.process(new ProcessRequest[] { psr })[0];
        if (p_res.isSuccess()) {
            // Since the submission was successful we can now approve or reject it with
            // a ProcessWorkItmeRequest
            ProcessWorkitemRequest pwr = new ProcessWorkitemRequest();
            pwr.setAction("Approve");
            pwr.setComments("This request was approved from the API.");
            pwr.setWorkitemId(p_res.getNewWorkitemIds(0));
            p_res = binding.process(new ProcessRequest[] { pwr })[0];
            if (p_res.isSuccess()) {
                System.out.println("Successfully submitted and then approved an approval request.");
            } else {
                System.out.println("Error approving the work item: " + p_res.getErrors(0).getMessage());
            }
        } else {
            System.out.println("Error submitting the account for approval: " + p_res.getErrors(0).getMessage());
        }
    } catch (ApiFault e) {
        System.out.println("The API returned a fault: " + e.getExceptionMessage());
    } catch (RemoteException e) {
        System.out.println("There was an Axis generated error: " + e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
    }
    getUserInput("\nHit the enter key to continue...");
}
Also used : ApiFault(com.salesforce.soap.partner.fault.ApiFault) ProcessRequest(com.salesforce.soap.partner.ProcessRequest) ProcessWorkitemRequest(com.salesforce.soap.partner.ProcessWorkitemRequest) SObject(com.salesforce.soap.partner.sobject.SObject) ProcessResult(com.salesforce.soap.partner.ProcessResult) ProcessSubmitRequest(com.salesforce.soap.partner.ProcessSubmitRequest) RemoteException(java.rmi.RemoteException) RemoteException(java.rmi.RemoteException) ServiceException(javax.xml.rpc.ServiceException) IOException(java.io.IOException)

Aggregations

ProcessRequest (com.salesforce.soap.partner.ProcessRequest)1 ProcessResult (com.salesforce.soap.partner.ProcessResult)1 ProcessSubmitRequest (com.salesforce.soap.partner.ProcessSubmitRequest)1 ProcessWorkitemRequest (com.salesforce.soap.partner.ProcessWorkitemRequest)1 ApiFault (com.salesforce.soap.partner.fault.ApiFault)1 SObject (com.salesforce.soap.partner.sobject.SObject)1 IOException (java.io.IOException)1 RemoteException (java.rmi.RemoteException)1 ServiceException (javax.xml.rpc.ServiceException)1