When i'm trying to use the singleEmailMessage i get the following error:
System.EmailException: SendEmail failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Email body is required.
However in my code(below) i specify the email body, what am i missing here?
public void finish(Database.BatchableContext bc){
String[] toAddresses = new String[] {'[email protected]'}; //System Admin E-mail
String emailBody;
if(!errors.isEmpty()) {
System.debug('notEmpty');
for(Exception error : errors)
{
emailBody += error + '\n';
}
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setSubject('Errors occurred during batch process.');
mail.setToAddresses(toAddresses);
mail.setSaveAsActivity(false);
mail.setPlainTextBody(emailBody);
Messaging.sendEmail(new Messaging.Email[] { mail });
}
}