0

I want to see the records that are failed via Database.UpsertResult. Need to check the error Message and Some required field values like Case Subject, Description other custom fields

Schema.SObjectField f = Case.Ticket_Number__c; 
Database.UpsertResult [] cr = Database.upsert(toBeUpsertCases, f, false);  
for(Database.upsertResult result:cr) {
    if (!result.isSuccess()){ 
        string error = result.getId() + ',' + ' CASE ' + ',' + result.getErrors() + '\n';
        System.debug(error); 
    }
}

In the code above, "error" is printing null, along with the CASE and error message. I need the values of the fields that were used for assignment to be included in the error message as well.

Can you help me is that possible to get the other field values

0

1 Answer 1

2

The entries in the Database.UpsertResult[] array are in the same order as the original list. So you can use something like this to handle the results

Schema.SObjectField f = Case.Ticket_Number__c; 
Database.UpsertResult [] cr = Database.upsert(toBeUpsertCases, f, false);  
for(Integer i=0; i<cr.size(); i++) {
    Database.upsertResult result = cr[i];
    Case sourceRecord = toBeUpsertCases[i];
    if (!result.isSuccess()){ 
        string error = result.getId() + ',' + ' CASE ' + ',' + result.getErrors() + '\n';
        System.debug(error); 
    }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .