use of com.sforce.soap.partner.UpsertResult in project components by Talend.
the class SalesforceWriter method doUpsert.
private UpsertResult[] doUpsert() throws IOException {
if (upsertItems.size() > 0) {
// Clean the feedback records at each batch write.
cleanWrites();
SObject[] upds = new SObject[upsertItems.size()];
for (int i = 0; i < upsertItems.size(); i++) {
upds[i] = createSObjectForUpsert(upsertItems.get(i));
}
String[] changedItemKeys = new String[upds.length];
for (int ix = 0; ix < upds.length; ++ix) {
Object value = upds[ix].getField(upsertKeyColumn);
if (value != null) {
changedItemKeys[ix] = String.valueOf(value);
}
}
UpsertResult[] upsertResults;
try {
upsertResults = connection.upsert(upsertKeyColumn, upds);
upds = null;
if (upsertResults != null && upsertResults.length != 0) {
int batch_idx = -1;
for (int i = 0; i < upsertResults.length; i++) {
++batch_idx;
if (upsertResults[i].getSuccess()) {
if (upsertResults[i].getCreated()) {
handleSuccess(upsertItems.get(i), upsertResults[i].getId(), "created");
} else {
handleSuccess(upsertItems.get(i), upsertResults[i].getId(), "updated");
}
} else {
handleReject(upsertItems.get(0), upsertResults[i].getErrors(), changedItemKeys, batch_idx);
}
}
}
upsertItems.clear();
return upsertResults;
} catch (ConnectionException e) {
throw new IOException(e);
}
}
return null;
}
Aggregations