Let's assume I have a list of 100 new records that I want to insert, 10 of these records are missing information which will result in DML exception.
Is there a way for me to create a list and include all the problematic records in it?
Let's assume I have a list of 100 new records that I want to insert, 10 of these records are missing information which will result in DML exception.
Is there a way for me to create a list and include all the problematic records in it?
You can use the SaveResult Class methods.
If you insert the records using Database.insert
/ Database.update
with a false second parameter (allOrNothing) to allow partial processing of records on failure you will be able to retrieve an array of SaveResult objects. Each of those SaveResult records has a isSuccess() method which returns false in case the DML operation was not successful. From there you are able to retrieve the specific error per record that failed to be inserted and/or updated.
If you want to do the same for a Database.delete
method instead then you need to use the DeleteResult class.