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?
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.Sign up to join this community
You can use the SaveResult Class methods.
If you insert the records using Database.insert 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/updated/deleted.