use of com.salesforce.soap.partner.MergeResult in project tdi-studio-se by Talend.
the class PartnerSamples method mergeSample.
private void mergeSample() {
// call the login function to do so
if (!loggedIn) {
if (!login()) {
return;
}
}
try {
SObject masterAccount = new SObject();
MessageElement masterAccountName = newMessageElement("Name", "MasterAccount");
masterAccount.set_any(new MessageElement[] { masterAccountName });
masterAccount.setType("Account");
SaveResult masterAccountSaveResult;
masterAccountSaveResult = binding.create(new SObject[] { masterAccount })[0];
masterAccount.setId(masterAccountSaveResult.getId());
MessageElement masterAccountDescription = newMessageElement("Description", "Old description");
masterAccount.set_any(new MessageElement[] { masterAccountName, masterAccountDescription });
SObject accountToMerge = new SObject();
accountToMerge.setType("Account");
MessageElement mergeAccountName = newMessageElement("Name", "AccountToMerge");
MessageElement mergeAccountDesc = newMessageElement("Description", "Duplicate account");
accountToMerge.set_any(new MessageElement[] { mergeAccountDesc, mergeAccountName });
SaveResult accountToMergeSaveResult = binding.create(new SObject[] { accountToMerge })[0];
// Attach a note, which will get re-parented
SObject note = new SObject();
note.setType("Note");
MessageElement noteParentId = newMessageElement("ParentId", accountToMergeSaveResult.getId());
MessageElement noteBody = newMessageElement("Body", "This note will be moved to the MasterAccount during merge.");
MessageElement noteTitle = newMessageElement("Title", "Test note to be reparented.");
note.set_any(new MessageElement[] { noteBody, noteParentId, noteTitle });
@SuppressWarnings("unused") SaveResult noteSave = binding.create(new SObject[] { note })[0];
MergeRequest mr = new MergeRequest();
// Perform an update on the master record as part of the merge:
masterAccountDescription = newMessageElement("Description", "Was merged");
masterAccount.set_any(new MessageElement[] { masterAccountName, masterAccountDescription });
mr.setMasterRecord(masterAccount);
mr.setRecordToMergeIds(new String[] { accountToMergeSaveResult.getId() });
MergeResult result = binding.merge(new MergeRequest[] { mr })[0];
getUserInput("Merged " + result.isSuccess() + " got " + result.getUpdatedRelatedIds().length + " updated child records\nHit return to continue.");
} catch (ApiFault e) {
System.out.println("Error merging account: " + e.getExceptionMessage());
getUserInput("\nHit return to continue...");
} catch (RemoteException e) {
System.out.println("Error from the server on the merge sample: " + e.getMessage());
getUserInput("\nHit return to continue...");
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations