use of com.salesforce.soap.partner.sobject.SObject 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.sobject.SObject in project tdi-studio-se by Talend.
the class SforceManagementImpl method logout.
/**
* logout
*/
@Override
public void logout() throws Exception {
Object returnObject = null;
// if there are still records to be commited:
try {
if (insertItems.size() > 0) {
SObject[] accs = insertItems.toArray(new SObject[insertItems.size()]);
String[] changedItemKeys = new String[accs.length];
Create create = new Create();
create.setSObjects(accs);
SaveResult[] sr = sforceConn.create(create).getResult();
insertItems.clear();
accs = null;
if (sr != null && sr.length != 0) {
int batch_idx = -1;
for (SaveResult result : sr) {
++batch_idx;
StringBuilder errors = new StringBuilder("");
if (result.getSuccess()) {
// TODO: send back the ID
} else {
errors = addLog(result.getErrors(), batch_idx < changedItemKeys.length ? "" + (batch_idx + 1) : "Batch index out of bounds");
}
if (exceptionForErrors && errors.toString().length() > 0) {
if (logWriter != null) {
logWriter.close();
}
throw new Exception(errors.toString());
}
}
}
returnObject = sr;
}
if (deleteItems.size() > 0) {
ID[] delIDs = deleteItems.toArray(new ID[deleteItems.size()]);
String[] changedItemKeys = new String[delIDs.length];
for (int ix = 0; ix < delIDs.length; ++ix) {
changedItemKeys[ix] = delIDs[ix].getID();
}
Delete dels = new Delete();
dels.setIds(delIDs);
DeleteResponse dresp = sforceConn.delete(dels);
DeleteResult[] dr = dresp.getResult();
deleteItems.clear();
delIDs = null;
if (dr != null && dr.length != 0) {
int batch_idx = -1;
for (DeleteResult result : dr) {
++batch_idx;
StringBuilder errors = new StringBuilder("");
if (result.getSuccess()) {
// TODO: send back the ID
} else {
errors = addLog(result.getErrors(), batch_idx < changedItemKeys.length ? changedItemKeys[batch_idx] : "Batch index out of bounds");
}
if (exceptionForErrors && errors.toString().length() > 0) {
if (logWriter != null) {
logWriter.close();
}
throw new Exception(errors.toString());
}
}
}
returnObject = dr;
}
if (updateItems.size() > 0) {
SObject[] upds = updateItems.toArray(new SObject[updateItems.size()]);
String[] changedItemKeys = new String[upds.length];
for (int ix = 0; ix < upds.length; ++ix) {
changedItemKeys[ix] = upds[ix].getId().getID();
}
Update update = new Update();
update.setSObjects(upds);
SaveResult[] saveResults = sforceConn.update(update).getResult();
updateItems.clear();
upds = null;
if (saveResults != null && saveResults.length != 0) {
int batch_idx = -1;
for (SaveResult result : saveResults) {
++batch_idx;
StringBuilder errors = new StringBuilder("");
if (result.getSuccess()) {
// TODO: send back the ID
} else {
errors = addLog(result.getErrors(), batch_idx < changedItemKeys.length ? changedItemKeys[batch_idx] : "Batch index out of bounds");
}
if (exceptionForErrors && errors.toString().length() > 0) {
if (logWriter != null) {
logWriter.close();
}
throw new Exception(errors.toString());
}
}
}
returnObject = saveResults;
}
if (upsertItems.size() > 0) {
SObject[] upds = upsertItems.toArray(new SObject[upsertItems.size()]);
String[] changedItemKeys = new String[upds.length];
for (int ix = 0; ix < upds.length; ++ix) {
changedItemKeys[ix] = "No value for " + upsertKeyColumn + " ";
OMElement[] oms = upds[ix].getExtraElement();
for (OMElement om : oms) {
if (upsertKeyColumn != null && om != null && upsertKeyColumn.equals(om.getLocalName())) {
changedItemKeys[ix] = om.getText();
break;
}
}
}
Upsert upsert = new Upsert();
upsert.setSObjects(upds);
upsert.setExternalIDFieldName(upsertKeyColumn);
UpsertResult[] upsertResults = sforceConn.upsert(upsert).getResult();
upsertItems.clear();
upds = null;
if (upsertResults != null && upsertResults.length != 0) {
int batch_idx = -1;
for (UpsertResult result : upsertResults) {
++batch_idx;
StringBuilder errors = new StringBuilder("");
if (result.getSuccess()) {
// TODO: send back the ID
} else {
errors = addLog(result.getErrors(), batch_idx < changedItemKeys.length ? changedItemKeys[batch_idx] : "Batch index out of bounds");
}
if (exceptionForErrors && errors.toString().length() > 0) {
if (logWriter != null) {
logWriter.close();
}
throw new Exception(errors.toString());
}
}
}
returnObject = upsertResults;
}
} catch (Exception e) {
throw new Exception(e.toString());
}
if (logWriter != null) {
logWriter.close();
}
}
use of com.salesforce.soap.partner.sobject.SObject in project tdi-studio-se by Talend.
the class TopRecord method processOMElement.
private void processOMElement(OMElement ome, String prefixName) throws Exception {
if (ome.getChildElements().hasNext()) {
Iterator iter = ome.getChildElements();
// delete the fixed id and type elements when find firstly
int typeCount = 0;
int idCount = 0;
while (iter.hasNext()) {
Object objectValue = iter.next();
if (objectValue != null) {
if (objectValue instanceof OMElement) {
OMElement omeElem = (OMElement) objectValue;
if ("type".equals(omeElem.getLocalName()) && typeCount == 0) {
typeCount++;
continue;
}
if ("Id".equals(omeElem.getLocalName()) && idCount == 0) {
idCount++;
continue;
}
processOMElement(omeElem, prefixName + TopConfig.COLUMNNAME_DELIMTER + ome.getLocalName());
} else if (objectValue instanceof SObject) {
SObject sobject = (SObject) objectValue;
processSObject(sobject, prefixName + TopConfig.COLUMNNAME_DELIMTER + sobject.getType());
} else if (objectValue instanceof QueryResult) {
QueryResult queryResult = (QueryResult) objectValue;
processQueryResult(queryResult, prefixName);
} else {
throw new Exception("Unexcepted case happend...");
}
}
}
} else {
if (ome.getText() == null || "".equals(ome.getText())) {
return;
}
String newPrefixName = prefixName + TopConfig.COLUMNNAME_DELIMTER + ome.getLocalName();
// add the columnName to List one by one(order is important)
if (!columnNameList.contains(newPrefixName)) {
columnNameList.add(newPrefixName);
}
if (!columnLocalNameList.contains(ome.getLocalName())) {
columnLocalNameList.add(ome.getLocalName());
}
Object value = valueMap.get(newPrefixName);
if (value != null) {
valueMap.put(newPrefixName, value + TopConfig.VALUE_DELIMITER + ome.getText());
} else {
valueMap.put(newPrefixName, ome.getText());
}
}
}
use of com.salesforce.soap.partner.sobject.SObject in project tdi-studio-se by Talend.
the class TopRecord method processQueryResult.
private void processQueryResult(QueryResult qr, String prefixName) throws Exception {
for (int i = 0; i < qr.getRecords().length; i++) {
SObject record = qr.getRecords()[i];
processSObject(record, prefixName + TopConfig.COLUMNNAME_DELIMTER + record.getType());
}
}
use of com.salesforce.soap.partner.sobject.SObject 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