We have a future class which will call future class to send mail. Sometimes I get this mail from salesforce.
Apex script unhandled exception by user/organization: 005A00000062Q6O/00DA0000000YXoL Failed to invoke future method 'public static void sendEmail(Set)' on class 'AsyncApexClass' for job id '707A000004xKn9u' caused by: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_EMAIL_ADDRESS, From: invalid email address: 'Certification Support' <[email protected]>: [From__c] Class.AsyncApexClass.sendEmail: line 43, column 1
Below is my future class:
global class AsyncApexClass{
@future
public static void sendEmail(Set<Id> sendList){
List <Notes__c> notesList = new List<Notes__c>();
notesList.clear();
for(List<EmailMessage> emailmsglist:[select Id,parentId,Parent.Email__c,Parent.Contact.Email,ToAddress, FromAddress, Subject, TextBody, HTMLBody, CreatedDate from EmailMessage where id in :sendList] )
{
for(EmailMessage emlist :emailmsglist){
Notes__c note= new Notes__c(); // Create a note object
note.Case__c= emlist.parentid;
IF (emlist.HTMLBody != NULL && emlist.HTMLBody != ''){
note.Message__c = emlist.HTMLBody;
}
else {
note.Message__c = emlist.TextBody;
}
note.Sent_To__c = emlist.ToAddress;
note.From__c = emlist.FromAddress;
note.Subject__c = emlist.Subject;
note.Datetime_Created__c = emlist.CreatedDate;
if (emlist.Parent.Contact.Email == emlist.ToAddress || emlist.Parent.Email__c == emlist.ToAddress) // If the email is the same as Case's contact email or Email__c on Case itself, the type is a response.
{
note.Type__c = 'Response';
}
else {
note.Type__c = 'Forward/Others';
}
notesList.add(note); // Add note object to the list
}
}
// If the note list has records, insert the list.
if(notesList.size()>0) {
insert notesList;
}
}
}