3

I am currently trying to Update and Insert to collections of SObjects.

I perform the actions(update&insert) separately, obtaining a Database.SaveResult Array as feedback.

The problem is that I can't find out in an error scenario, which was the error that failed the Update/Insert of a certain SObject.

For example, I can easily determine if a record was Updated or Inserted successfully, by: 1. Iterating Dabase.SaveResult []

1.1- Checking if isSuccess? - Yes: Read the id of the record - Write some feedback info on it - No(is an error): How to derive here from a SaveResult instance, which SObject failed to update/insert?

Thank you! E.

7

The order of the SaveResult[] array matches the order of the inserted array.

List<Thing__c> myThings = new List<Thing__c>();

//... 

Database.SaveResult[] saveResults = Database.insert(myThings, false);

for (integer x=0; x<myThings.size(); x++) {
    //saveResults[x] is the saveResult of insert myThings[x]
}

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.