use of com.salesforce.soap.partner.ProcessSubmitRequest 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...");
}
Aggregations