You need to sign in to do that
Don't have an account?
JA-Dev
Handling exception during a partial save
Hi,
We have a batch job that updates a number of records and it could potentially throw a DML exception. I was trying to capture the ids of the records that caused an exception, but it seems that it won't return the ids. Here is a snippet of what it looks like:
Database.SaveResult[] lsr = Database.update(recordsToUpdate, false); for (Database.SaveResult sr : lsr) { if (sr.isSuccess()) { // This gets me the ids as expected successRecords = successRecords + sr.getId() + ','; else if (!sr.isSuccess()) { // This does not capture the ids of the failed records errorRecords = errorRecords + sr.getId() + ','; } }
Also, I saw that there is an Database.SaveResult.getErrors() function that I have not tried using yet. Would that give me the id of the failed record? I'm simply trying to capture any records that did not update, so that we can later reprocess.
Thanks in advance!
Per the Apex documentation for the 'getId' method: