use of com.sforce.soap.partner.SaveResult in project components by Talend.
the class SalesforceWriter method doUpdate.
private SaveResult[] doUpdate() throws IOException {
if (updateItems.size() > 0) {
// Clean the feedback records at each batch write.
cleanWrites();
SObject[] upds = new SObject[updateItems.size()];
for (int i = 0; i < updateItems.size(); i++) {
upds[i] = createSObject(updateItems.get(i));
}
String[] changedItemKeys = new String[upds.length];
for (int ix = 0; ix < upds.length; ++ix) {
changedItemKeys[ix] = upds[ix].getId();
}
SaveResult[] saveResults;
try {
saveResults = connection.update(upds);
upds = null;
if (saveResults != null && saveResults.length != 0) {
int batch_idx = -1;
for (int i = 0; i < saveResults.length; i++) {
++batch_idx;
if (saveResults[i].getSuccess()) {
handleSuccess(updateItems.get(i), saveResults[i].getId(), null);
} else {
handleReject(updateItems.get(i), saveResults[i].getErrors(), changedItemKeys, batch_idx);
}
}
}
updateItems.clear();
return saveResults;
} catch (ConnectionException e) {
throw new IOException(e);
}
}
return null;
}
use of com.sforce.soap.partner.SaveResult in project components by Talend.
the class SalesforceRuntimeTestUtil method createTestData.
public List<String> createTestData() throws ConnectionException {
this.login(SalesforceConnectionProperties.URL);
List<String> ids = new ArrayList<String>();
try {
List<SObject> contacts = new ArrayList<SObject>();
for (Map<String, String> row : testData) {
SObject contact = new SObject();
contact.setType(module);
contact.setField("FirstName", row.get("FirstName"));
contact.setField("LastName", row.get("LastName"));
contact.setField("Phone", row.get("Phone"));
contacts.add(contact);
}
SaveResult[] results = partnerConnection.create(contacts.toArray(new SObject[0]));
for (SaveResult result : results) {
if (result.isSuccess()) {
ids.add(result.getId());
} else {
for (int i = 0; i < result.getErrors().length; i++) {
com.sforce.soap.partner.Error err = result.getErrors()[i];
Assert.fail(err.getMessage());
}
}
}
} catch (ConnectionException ce) {
Assert.fail(ce.getMessage());
}
return ids;
}
use of com.sforce.soap.partner.SaveResult in project components by Talend.
the class SalesforceWriter method doInsert.
private SaveResult[] doInsert() throws IOException {
if (insertItems.size() > 0) {
// Clean the feedback records at each batch write.
cleanWrites();
SObject[] accs = new SObject[insertItems.size()];
for (int i = 0; i < insertItems.size(); i++) {
accs[i] = createSObject(insertItems.get(i));
}
String[] changedItemKeys = new String[accs.length];
SaveResult[] saveResults;
try {
saveResults = connection.create(accs);
if (saveResults != null && saveResults.length != 0) {
int batch_idx = -1;
for (int i = 0; i < saveResults.length; i++) {
++batch_idx;
if (saveResults[i].getSuccess()) {
handleSuccess(insertItems.get(i), saveResults[i].getId(), null);
} else {
handleReject(insertItems.get(i), saveResults[i].getErrors(), changedItemKeys, batch_idx);
}
}
}
insertItems.clear();
return saveResults;
} catch (ConnectionException e) {
throw new IOException(e);
}
}
return null;
}
use of com.sforce.soap.partner.SaveResult in project components by Talend.
the class SalesforceRuntimeTestUtil method createTestData.
public List<String> createTestData() throws ConnectionException {
this.login(SalesforceConnectionProperties.URL);
List<String> ids = new ArrayList<String>();
try {
List<SObject> contacts = new ArrayList<SObject>();
for (Map<String, String> row : testData) {
SObject contact = new SObject();
contact.setType(module);
contact.setField("FirstName", row.get("FirstName"));
contact.setField("LastName", row.get("LastName"));
contact.setField("Phone", row.get("Phone"));
contacts.add(contact);
}
SaveResult[] results = partnerConnection.create(contacts.toArray(new SObject[0]));
for (SaveResult result : results) {
if (result.isSuccess()) {
ids.add(result.getId());
} else {
for (int i = 0; i < result.getErrors().length; i++) {
com.sforce.soap.partner.Error err = result.getErrors()[i];
Assert.fail(err.getMessage());
}
}
}
} catch (ConnectionException ce) {
Assert.fail(ce.getMessage());
}
return ids;
}
Aggregations