use of com.salesforce.soap.partner.SearchRecord in project tdi-studio-se by Talend.
the class PartnerSamples method searchSample.
private void searchSample() {
// call the login function to do so
if (!loggedIn) {
if (!login()) {
return;
}
}
SearchResult sr = null;
QueryResult qr = null;
try {
sr = binding.search("find {4159017000} in phone fields returning contact(id, phone, firstname, lastname), lead(id, phone, firstname, lastname), account(id, phone, name)");
SearchRecord[] records = sr.getSearchRecords();
Vector contacts = new Vector();
Vector leads = new Vector();
Vector accounts = new Vector();
if (records != null && records.length > 0) {
for (int i = 0; i < records.length; i++) {
SObject record = records[i].getRecord();
if (record.getType().toLowerCase().equals("contact")) {
contacts.add(record);
} else if (record.getType().toLowerCase().equals("lead")) {
leads.add(record);
} else if (record.getType().toLowerCase().equals("account")) {
accounts.add(record);
}
}
if (contacts.size() > 0) {
System.out.println("Found " + new Integer(contacts.size()).toString() + " contacts:");
for (int i = 0; i < contacts.size(); i++) {
SObject c = (SObject) contacts.get(i);
System.out.println(c.getId() + " - " + c.get_any()[1] + " " + c.get_any()[2] + " - " + c.get_any()[0]);
}
}
if (leads.size() > 0) {
System.out.println("Found " + new Integer(leads.size()).toString() + " leads:");
for (int i = 0; i < leads.size(); i++) {
SObject l = (SObject) leads.get(i);
System.out.println(l.getId() + " - " + l.get_any()[1] + " " + l.get_any()[2] + " - " + l.get_any()[0]);
}
}
if (accounts.size() > 0) {
System.out.println("Found " + new Integer(accounts.size()).toString() + " accounts:");
for (int i = 0; i < accounts.size(); i++) {
SObject a = (SObject) accounts.get(i);
System.out.println(a.getId() + " - " + a.get_any()[1] + " - " + a.get_any()[0]);
}
}
} else {
System.out.println("No records were found for the search.");
}
System.out.println("\nSearch succesfully executed.");
getUserInput("\nHit return to continue...");
} catch (ApiFault af) {
System.out.println("\nFailed to execute search succesfully, error message was: \n" + af.getExceptionMessage());
getUserInput("\nHit return to continue...");
} catch (Exception ex) {
System.out.println("\nFailed to execute search succesfully, error message was: \n" + ex.getMessage());
getUserInput("\nHit return to continue...");
}
}
Aggregations