use of com.salesforce.soap.partner.sobject.SObject in project tdi-studio-se by Talend.
the class PartnerSamples method getUnconvertedLead.
private SObject getUnconvertedLead() throws Exception {
SObject leadToReturn = null;
// get a list of leads so the user can select one
QueryResult qr = binding.query("Select Id, FirstName, LastName from Lead where ConvertedDate = Null");
if (qr.getSize() == 0) {
// No leads where found that have not been
// converted, so....
// we will create a lead and then run the query again
System.out.println("No unconverted leads found, will create one for you...");
createLeadSample();
qr = binding.query("Select Id, FirstName, LastName from Lead where ConvertedDate = Null");
}
if (qr.getSize() > 0) {
for (int i = 0; i < qr.getRecords().length; i++) {
SObject lead = qr.getRecords()[i];
System.out.println(new Integer(i + 1).toString() + ": " + getFieldValue(lead.get_any(), "FirstName") + " " + getFieldValue(lead.get_any(), "LastName"));
}
String selectedLead = getUserInput("/nSelect the number of the lead to convert. ");
if (selectedLead != null) {
try {
int selLead = new Integer(selectedLead).intValue();
leadToReturn = qr.getRecords(selLead - 1);
} catch (Exception ex) {
System.out.println("The number you selected is not valid, conversion failed...");
}
}
}
if (leadToReturn == null) {
throw new Exception("No lead selected, required data, conversion failed");
} else {
return leadToReturn;
}
}
use of com.salesforce.soap.partner.sobject.SObject 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();
}
}
use of com.salesforce.soap.partner.sobject.SObject in project tdi-studio-se by Talend.
the class PartnerSamples method getAccount.
private SObject getAccount() throws Exception {
SObject accountToReturn = null;
// get a list of Accounts so the user can select one
QueryResult qr = binding.query("Select Id, Name from Account");
if (qr.getSize() == 0) {
// No accounts found (Not Likely), so...
// we will create an account and then run the query again
this.createAccountSample();
qr = binding.query("Select Id, Name from Account");
}
if (qr.getSize() > 0) {
for (int i = 0; i < qr.getRecords().length; i++) {
SObject account = qr.getRecords(i);
System.out.println(new Integer(i + 1).toString() + ": " + getFieldValue(account.get_any(), "Name"));
}
String selectedAccount = getUserInput("/nSelect the number of the account to use. ");
if (selectedAccount != null) {
try {
int selAccount = new Integer(selectedAccount).intValue();
accountToReturn = qr.getRecords(selAccount - 1);
} catch (Exception ex) {
System.out.println("The number you selected is not valid, exiting...");
}
}
}
if (accountToReturn == null) {
throw new Exception("Bad account selection, conversion failed.");
} else {
return accountToReturn;
}
}
use of com.salesforce.soap.partner.sobject.SObject in project tdi-studio-se by Talend.
the class PartnerSamples method createContactSample.
private void createContactSample() {
// call the login function to do so
if (!loggedIn) {
if (!login()) {
return;
}
}
try {
SObject[] cons = new SObject[2];
MessageElement[] contact;
for (int j = 0; j < cons.length; j++) {
int index = 0;
if (accounts != null) {
contact = new MessageElement[18];
contact[index++] = newMessageElement("AccountId", accounts[0]);
} else {
contact = new MessageElement[17];
}
contact[index++] = newMessageElement("AssistantName", "Jane");
contact[index++] = newMessageElement("AssistantPhone", "777.777.7777");
contact[index++] = newMessageElement("Department", "Purchasing");
contact[index++] = newMessageElement("Description", "International IT Purchaser");
contact[index++] = newMessageElement("Email", "joeblow@isp.com");
contact[index++] = newMessageElement("Fax", "555.555.5555");
contact[index++] = newMessageElement("MailingCity", "San Mateo");
contact[index++] = newMessageElement("MailingCountry", "US");
contact[index++] = newMessageElement("MailingState", "CA");
contact[index++] = newMessageElement("MailingStreet", "1129 B Street");
contact[index++] = newMessageElement("MailingPostalCode", "94105");
contact[index++] = newMessageElement("MobilePhone", "888.888.8888");
contact[index++] = newMessageElement("FirstName", "Joe");
contact[index++] = newMessageElement("LastName", "Blow");
contact[index++] = newMessageElement("Salutation", "Mr.");
contact[index++] = newMessageElement("Phone", "999.999.9999");
contact[index++] = newMessageElement("Title", "Purchasing Director");
cons[j] = new SObject();
cons[j].setType("Contact");
cons[j].set_any(contact);
}
SaveResult[] sr = binding.create(cons);
for (int j = 0; j < sr.length; j++) {
if (sr[j].isSuccess()) {
System.out.println("A contact was create with an id of: " + sr[j].getId());
if (accounts != null) {
System.out.println(" - the contact was associated with the account you created with an id of " + accounts[0] + ".");
}
if (contacts == null) {
contacts = new String[] { sr[j].getId() };
} else {
String[] tempContacts = null;
tempContacts = new String[contacts.length + 1];
for (int i = 0; i < contacts.length; i++) {
tempContacts[i] = contacts[i];
}
tempContacts[contacts.length] = sr[j].getId();
contacts = tempContacts;
}
} else {
// array and write them to the screen
for (int i = 0; i < sr[j].getErrors().length; i++) {
// get the next error
com.salesforce.soap.partner.Error err = sr[j].getErrors()[i];
System.out.println("Errors were found on item " + new Integer(j).toString());
System.out.println("Error code is: " + err.getStatusCode().toString());
System.out.println("Error message: " + err.getMessage());
}
}
}
getUserInput("\nHit return to continue...");
} catch (ApiFault af) {
System.out.println("\nFailed to create contacts, error message was: \n" + af.getExceptionMessage());
getUserInput("\nHit return to continue...");
} catch (Exception ex) {
System.out.println("\nFailed to create contacts, error message was: \n" + ex.getMessage());
getUserInput("\nHit return to continue...");
}
}
use of com.salesforce.soap.partner.sobject.SObject in project tdi-studio-se by Talend.
the class PartnerSamples method updateAccountSample.
private void updateAccountSample() {
// call the login function to do so
if (!loggedIn) {
if (!login()) {
return;
}
}
try {
// check to see if there are any accounts created in this session
if (accounts == null) {
System.out.println("\nUpdate operation not completed. You will need to create an account during this session to run the update sample.");
getUserInput("\nHit return to continue...");
return;
}
// create the account object to hold our changes
SObject updateAccount = new SObject();
updateAccount.setType("Account");
// need to have the id so that web service knows which account to
// update
updateAccount.setId(accounts[0]);
// set a new value for the name property
MessageElement[] ufields = new MessageElement[1];
ufields[0] = newMessageElement("Name", "New Account Name from Update Sample");
updateAccount.set_any(ufields);
// create one that will throw an error
SObject errorAccount = new SObject();
errorAccount.setType("Account");
errorAccount.setId(new String("SLFKJLFKJ"));
errorAccount.setFieldsToNull(new String[] { "Name" });
// call the update passing an array of object
SaveResult[] saveResults = binding.update(new SObject[] { updateAccount, errorAccount });
// loop through the results, checking for errors
for (int j = 0; j < saveResults.length; j++) {
System.out.println("Item: " + new Integer(j).toString());
if (saveResults[j].isSuccess()) {
System.out.println("An account with an id of: " + saveResults[j].getId() + " was updated.\n");
} else {
System.out.println("Item " + new Integer(j).toString() + " had an error updating.");
System.out.println(" The error reported was: " + saveResults[j].getErrors()[0].getMessage() + "\n");
}
}
} catch (ApiFault af) {
System.out.println("\nFailed to succesfully update an account, error message was: \n" + af.getExceptionMessage());
getUserInput("\nHit return to continue...");
} catch (Exception ex) {
System.out.println("\nFailed to succesfully update an account, error message was: \n" + ex.getMessage());
}
getUserInput("\nHit return to continue...");
}
Aggregations