I have a batch job that tries to handle any DML exceptions and write them to a separate Custom object called Feed_Log__c
.
I have sometimes getting a Null pointer exception after trying to handle a UNABLE_TO_LOCK_ROW
exception. Here is my catch block:
catch(DmlException e){
feedLogToInsert.Status__c = 'Aborted';
feedLogToInsert.Status_Message__c = 'Project-DmlException';
for (Integer i = 0; i < e.getNumDml(); i++) {
feedLogToInsert.Error_Count__c++;
if(feedLogToInsert.Exception_Message__c == ''){
feedLogToInsert.Exception_Message__c = e.getDmlId(i) + '-' + e.getDmlMessage(i);
}
else{
// Check to see if we will overrun our TextArea.. only copy if not
// Also, added Id of offending record
Integer insertLen = e.getDmlMessage(i).length() + 18;
if ((feedLogToInsert.Exception_Message__c.length() + insertLen) < 32768) {
feedLogToInsert.Exception_Message__c += ', ' + e.getDmlId(i) + '-' + e.getDmlMessage(i);
} else {
System.debug(LoggingLevel.ERROR,'(BatchCarlProject) DML err: ' + e.getDmlId(i) + '-' + e.getDmlMessage(i));
}
}
}
Database.rollback(sp);
}
I looked at the DML Exception class, and cannot see any reason why I
would get a Null pointer exception as I iterate over all of the e.getNumDml()
entries.
If anyone can shed light on this, I would appreciate it...
Oh, and apologies for the hard-coded 32768, but I could not find any way to find the size of the text area, such as the "C" language "sizeof" offers.