use of com.salesforce.soap.partner.fault.ApiFault 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...");
}
}
use of com.salesforce.soap.partner.fault.ApiFault in project tdi-studio-se by Talend.
the class PartnerSamples method getServerTimestampSample.
private void getServerTimestampSample() {
if (!loggedIn) {
if (!login()) {
return;
}
}
System.out.println("\nGetting server's timestamp...");
try {
Calendar cal = binding.getServerTimestamp().getTimestamp();
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
df.setCalendar(cal);
System.out.println("Time stamp on server: " + df.format(cal.getTime()));
} catch (ApiFault af) {
System.out.println("ERROR: getting server timestamp.\n" + af.getExceptionMessage());
getUserInput("\nHit return to continue...");
} catch (RemoteException ex2) {
System.out.println("ERROR: getting server timestamp.\n" + ex2.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 getDeletedSample.
private void getDeletedSample() {
// call the login function to do so
if (!loggedIn) {
if (!login()) {
return;
}
}
try {
// Calendar deletedDate
GregorianCalendar cal = (GregorianCalendar) binding.getServerTimestamp().getTimestamp();
GregorianCalendar calEnd = (GregorianCalendar) cal.clone();
cal.add(GregorianCalendar.MINUTE, -5);
GetDeletedResult mr = binding.getDeleted("Contact", cal, calEnd);
if (mr.getDeletedRecords() != null) {
for (int i = 0; i < mr.getDeletedRecords().length; i++) {
System.out.println(mr.getDeletedRecords(i).getId() + " was deleted on " + mr.getDeletedRecords(i).getDeletedDate().getTime().toString());
}
} else {
System.out.println("No deletions from contacts in the last 5 minutes.");
}
getUserInput("\nHit return to continue...");
} catch (ApiFault af) {
System.out.println("\nFailed to get deleted records, error message was: \n" + af.getExceptionMessage());
getUserInput("\nHit return to continue...");
} catch (Exception ex) {
System.out.println("\nFailed to get deleted records, 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 getUpdatedSample.
private void getUpdatedSample() {
// call the login function to do so
if (!loggedIn) {
if (!login()) {
return;
}
}
try {
// Calendar deletedDate
GregorianCalendar cal = (GregorianCalendar) binding.getServerTimestamp().getTimestamp();
GregorianCalendar calEnd = (GregorianCalendar) cal.clone();
cal.add(GregorianCalendar.MINUTE, -5);
GetUpdatedResult mr = binding.getUpdated("Account", cal, calEnd);
if (mr.getIds() != null && mr.getIds().length > 0) {
for (int i = 0; i < mr.getIds().length; i++) {
System.out.println(mr.getIds(i) + " was updated.");
}
} else {
System.out.println("No updates to accounts in the last 5 minutes.");
}
getUserInput("\nHit return to continue...");
} catch (ApiFault af) {
System.out.println("\nFailed to get updated records, error message was: \n" + af.getExceptionMessage());
getUserInput("\nHit return to continue...");
} catch (Exception ex) {
System.out.println("\nFailed to get updated records, 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 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