Friday, 7 August 2020

Get Database.SaveResult error and sucesses list

 

To get the Error for Database.update which can be used in Classes

if (accountstoUpd.size() > 0) {

Database.SaveResult[] lsr = Database.update(accountstoUpd,false);

Integer recordid = 0;

for (Database.SaveResult SR : lsr) {

if (!SR.isSuccess()) {

this.errormsgs += 'Account Record:' + accountstoUpd[recordid].id + ', ' + SR.getErrors()[0].getMessage() + '<br/>';

}

recordid++;

}

}

if (this.errormsgs.length() > 0) {

ErrorLogs__c errtoSave = new ErrorLogs__c(details__c = this.errormsgs);

insert errtoSave;

}

No comments:

Post a Comment