0

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?

  • Are you running an anonymous apex script, inserting using an apex class, or using a tool such as dataloader? – bpilling Feb 26 at 10:10
  • I want to build a class that sends out emails to the developers if there is an issue/error. – Json Feb 26 at 10:21
  • this can help probably salesforce.stackexchange.com/questions/42417/… – User6670 Feb 26 at 10:41
3

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.