0

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

1 Answer 1

0

I believe it is due to what Salesforce interprets as valid address. From this article

For the local part of the email address we accept the following characters. The local part is anything before the @ sign.

abcdefg.hijklmnopqrstuvwxyz!#$%&'*/=?^_+-`{|}~0123456789

Note: The character dot “.” is supported; provided that it is not the first character in the local-part

For the domain part of the email address we accept. The domain part is anything after the @ in an email address:

0-9 and A-Z and a-z and dash “-“

Example email address: abcdefg.hijklmnopqrstuvwxyz!#$%&'*/=?^_+-`{|}[email protected]

The following note.From__c = emlist.FromAddress; is storing a wrong format (accordign to salesforce) i.e. [email protected].

2
  • I changed the email format as per your suggestion. Still I am getting the same error.
    – AJoshi
    Jun 6, 2018 at 6:21
  • Can you update the question with your error?
    – manjit5190
    Jun 6, 2018 at 16:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .