use of com.salesforce.soap.partner.DeleteResult in project tdi-studio-se by Talend.
the class PartnerSamples method createAndDeleteAnAccount.
private String createAndDeleteAnAccount(String accountName) {
String returnId = null;
SObject acct = new SObject();
acct.setType("Account");
String acctName = (accountName == null) ? "QueryAll Sample" : accountName;
try {
MessageElement nameField = newMessageElement("Name", acctName);
acct.set_any(new MessageElement[] { nameField });
// We are only creating one account so we can index the return array directly
SaveResult sr = binding.create(new SObject[] { acct })[0];
if (sr.isSuccess()) {
acct.setId(sr.getId());
// Ok, now we will delete that account
DeleteResult dr = binding.delete(new String[] { acct.getId() })[0];
if (!dr.isSuccess()) {
System.out.println("The web service would not let us delete the account: \n" + dr.getErrors(0).getMessage());
getUserInput("\nHit return to continue...");
} else {
returnId = acct.getId();
}
} else {
System.out.println("The web service would not let us create the account: \n" + sr.getErrors(0).getMessage());
getUserInput("\nHit return to continue...");
}
} catch (ApiFault e) {
System.out.println("Error creating test account: " + e.getExceptionMessage());
getUserInput("\nHit return to continue...");
} catch (RemoteException e) {
System.out.println("Error from the server on create test account: " + e.getMessage());
getUserInput("\nHit return to continue...");
} catch (Exception e) {
e.printStackTrace();
}
return returnId;
}
use of com.salesforce.soap.partner.DeleteResult in project tdi-studio-se by Talend.
the class SforceManagementImpl method readResult.
@Override
public Map<String, String> readResult(Object[] results) throws Exception {
Map<String, String> resultMessage = null;
if (results instanceof SaveResult[]) {
for (SaveResult result : (SaveResult[]) results) {
resultMessage = new HashMap<String, String>();
if (result.getId() != null) {
resultMessage.put("id", result.getId().getID());
}
resultMessage.put("success", String.valueOf(result.getSuccess()));
if (!result.getSuccess()) {
for (Error error : result.getErrors()) {
if (error.getStatusCode() != null) {
resultMessage.put("StatusCode", error.getStatusCode().toString());
}
if (error.getFields() != null) {
StringBuffer fields = new StringBuffer();
for (String field : error.getFields()) {
fields.append(field);
fields.append(",");
}
if (fields.length() > 0) {
fields.deleteCharAt(fields.length() - 1);
}
resultMessage.put("Fields", fields.toString());
}
resultMessage.put("Message", error.getMessage());
}
}
}
return resultMessage;
} else if (results instanceof DeleteResult[]) {
for (DeleteResult result : (DeleteResult[]) results) {
resultMessage = new HashMap<String, String>();
if (result.getId() != null) {
resultMessage.put("id", result.getId().getID());
}
resultMessage.put("success", String.valueOf(result.getSuccess()));
if (!result.getSuccess()) {
for (Error error : result.getErrors()) {
if (error.getStatusCode() != null) {
resultMessage.put("StatusCode", error.getStatusCode().toString());
}
resultMessage.put("Message", error.getMessage());
}
}
}
return resultMessage;
} else if (results instanceof UpsertResult[]) {
for (UpsertResult result : (UpsertResult[]) results) {
resultMessage = new HashMap<String, String>();
if (result.getId() != null) {
resultMessage.put("id", result.getId().getID());
}
resultMessage.put("success", String.valueOf(result.getSuccess()));
resultMessage.put("created", String.valueOf(result.getCreated()));
if (!result.getSuccess()) {
for (Error error : result.getErrors()) {
if (error.getStatusCode() != null) {
resultMessage.put("StatusCode", error.getStatusCode().toString());
}
if (error.getFields() != null) {
StringBuffer fields = new StringBuffer();
for (String field : error.getFields()) {
fields.append(field);
fields.append(",");
}
if (fields.length() > 0) {
fields.deleteCharAt(fields.length() - 1);
}
resultMessage.put("Fields", fields.toString());
}
resultMessage.put("Message", error.getMessage());
}
}
}
return resultMessage;
}
return null;
}
use of com.salesforce.soap.partner.DeleteResult 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.DeleteResult in project tdi-studio-se by Talend.
the class SforceManagementImpl method delete.
/**
* delete, one time one record.
*/
@Override
public DeleteResult[] delete(String id) throws Exception {
if (id == null) {
return null;
}
// String[] ids = new String[] { id };
ID dID = new ID();
dID.setID(id);
deleteItems.add(dID);
if (deleteItems.size() >= commitLevel) {
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());
}
}
}
return dr;
}
return null;
}
Aggregations