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;
}