use of com.salesforce.soap.partner.fault.ApiFault in project tdi-studio-se by Talend.
the class PartnerSamples method queryAllSample.
private void queryAllSample() {
// call the login function to do so
if (!loggedIn) {
if (!login()) {
return;
}
}
// For this sample we will create an account and then delete it
// to demonstrate the power of queryAll
String accountName = getUserInput("\nEnter a name for a test account:");
if (accountName == null || accountName.length() == 0) {
return;
}
createAndDeleteAnAccount(accountName);
// Now for Query All. Query all allows you to return items that have been moved to the recycle
// bin, like the account we just deleted.
QueryResult qr = null;
try {
qr = binding.queryAll("select id, Name from Account where name = '" + accountName + "' and IsDeleted = true");
if (qr.getSize() != 0) {
SObject account = qr.getRecords()[0];
System.out.println("Retrieved the deleted account: " + getFieldValue(account.get_any(), "Name"));
} else {
System.out.println("Hmm...\nDid not find the account, that's strange.");
}
System.out.println("\nQuery succesfully executed.");
getUserInput("\nHit return to continue...");
} catch (ApiFault af) {
System.out.println("\nFailed to execute query succesfully, error message was: \n" + af.getExceptionMessage());
getUserInput("\nHit return to continue...");
} catch (Exception ex) {
System.out.println("\nFailed to execute query succesfully, error message was: \n" + ex.getMessage());
getUserInput("\nHit return to continue...");
}
}
use of com.salesforce.soap.partner.fault.ApiFault in project tdi-studio-se by Talend.
the class PartnerSamples method describeTabsSample.
private void describeTabsSample() {
if (!loggedIn) {
if (!login()) {
return;
}
}
try {
DescribeTabSetResult[] dtsrs = binding.describeTabs();
System.out.println("There are " + new Integer(dtsrs.length).toString() + " tabsets defined.");
for (int i = 0; i < dtsrs.length; i++) {
System.out.println("Tabset " + new Integer(i + 1).toString() + ":");
DescribeTabSetResult dtsr = dtsrs[i];
String tabSetLabel = dtsr.getLabel();
String logoUrl = dtsr.getLogoUrl();
boolean isSelected = dtsr.isSelected();
DescribeTab[] tabs = dtsr.getTabs();
System.out.println("Label is " + tabSetLabel + " logo url is " + logoUrl + ", there are " + new Integer(tabs.length) + " tabs defined in this set.");
for (int j = 0; j < tabs.length; j++) {
DescribeTab tab = tabs[j];
String tabLabel = tab.getLabel();
String objectName = tab.getSobjectName();
String tabUrl = tab.getUrl();
System.out.println("\tTab " + new Integer(j + 1) + ": \n\t\tLabel = " + tabLabel + "\n\t\tObject details on tab: " + objectName + "\n\t\t" + "Url to tab: " + tabUrl);
}
}
getUserInput("\nHit return to continue...");
} catch (ApiFault af) {
System.out.println("Failed to successfully describe tabs.\n\n" + af.getExceptionMessage());
getUserInput("\nHit return to continue...");
} catch (Exception ex) {
System.out.println("Failed to successfully describe tabs.\n\n" + ex.getMessage());
getUserInput("\nHit return to continue...");
}
}
use of com.salesforce.soap.partner.fault.ApiFault in project tdi-studio-se by Talend.
the class PartnerSamples method describeSoftphoneLayoutSample.
private void describeSoftphoneLayoutSample() {
if (!loggedIn) {
if (!login()) {
return;
}
}
try {
DescribeSoftphoneLayoutResult slr = binding.describeSoftphoneLayout();
DescribeSoftphoneLayoutCallType[] callTypes = slr.getCallTypes();
System.out.println("There are " + callTypes.length + " call types.");
for (int i = 0; i < callTypes.length; i++) {
DescribeSoftphoneLayoutCallType callType = callTypes[i];
DescribeSoftphoneLayoutInfoField[] fields = callType.getInfoFields();
System.out.println(" There are " + fields.length + " info fields.");
for (int j = 0; j < fields.length; j++) {
System.out.println("\t" + fields[j].getName() + "\n");
}
DescribeSoftphoneLayoutSection[] sections = callType.getSections();
System.out.println("\tThere are " + sections.length + " sections on this layout.");
for (int j = 0; j < sections.length; j++) {
DescribeSoftphoneLayoutSection section = sections[j];
DescribeSoftphoneLayoutItem[] items = section.getItems();
for (int k = 0; k < items.length; k++) {
DescribeSoftphoneLayoutItem item = items[k];
System.out.println("Section " + j + " - item api name: " + item.getItemApiName());
}
}
}
getUserInput("\nHit return to continue...");
} catch (ApiFault af) {
System.out.println("\nFailed to describe softphone layout, error message was: \n" + af.getExceptionMessage());
getUserInput("\nHit return to continue...");
} catch (Exception ex) {
System.out.println("\nFailed to describe softphone layout , error message was: \n" + ex.getMessage());
getUserInput("\nHit return to continue...");
}
}
use of com.salesforce.soap.partner.fault.ApiFault 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.fault.ApiFault in project tdi-studio-se by Talend.
the class PartnerSamples method loadQueryResults.
private ArrayList loadQueryResults(QueryResult qr) {
ArrayList returnVal = new ArrayList();
if (qr.getSize() > 0) {
boolean keepLooping = true;
while (keepLooping) {
for (int i = 0; i < qr.getRecords().length; i++) {
MessageElement[] records = qr.getRecords(i).get_any();
HashMap fields = new HashMap();
if (qr.getRecords(i).getId() != null)
fields.put("id", qr.getRecords(i).getId());
for (int j = 0; j < records.length; j++) {
MessageElement record = records[j];
if (!fields.containsKey(record.getName()))
fields.put(record.getName().toLowerCase(), record);
}
returnVal.add(fields);
}
if (qr.isDone())
keepLooping = false;
else
try {
qr = binding.queryMore(qr.getQueryLocator());
} catch (InvalidQueryLocatorFault e) {
System.out.println("\nFailed to query, error message was: \n" + e.getExceptionMessage());
getUserInput("\nHit return to continue...");
} catch (ApiFault af) {
System.out.println("\nFailed to query, error message was: \n" + af.getExceptionMessage());
getUserInput("\nHit return to continue...");
} catch (RemoteException e) {
e.printStackTrace();
getUserInput("\nHit return to continue...");
}
}
}
return returnVal;
}
Aggregations