function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kalaivani SubbaiyanKalaivani Subbaiyan 

Email is not triggering in TrailHead

On exploring a topic of “Get Started with Apex Triggers->Calling a Class Method from a Trigger” and found an issue in email send. The reference URL is https://trailhead.salesforce.com/en/content/learn/modules/apex_triggers/apex_triggers_intro (https://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Ftrailhead.salesforce.com%2Fen%2Fcontent%2Flearn%2Fmodules%2Fapex_triggers%2Fapex_triggers_intro&data=02%7C01%7CKalaivani.S%40academicpartnerships.com%7C9e204f268e8b413df08608d7c04ddbfa%7C8720e8557e2849ffa1a78d5e66b5659e%7C0%7C0%7C637189312958883426&sdata=y%2B6TkKarjuWhyCLT02pFMYwzrz6VLqJVB4t4PYF2NuQ%3D&reserved=0" originalsrc="https://trailhead.salesforce.com/en/content/learn/modules/apex_triggers/apex_triggers_intro" shash="r6IJIGnrjYA3GYR7WD6J0bypX1qlO/SqUeK3B5A/yjISYc0quYEpLBnH+E1ZCXuTIV3rlfxVylGduUA0VJ5KDYM0OheVncq/uPGWlwaKa8jxE6RmxJ0ulqAfX7YCtWxIBMSZH14DFcGsnVHAvO/IjFFCivGsuOFVBaC/H5QFEzQ=" style="color:#0563c1; text-decoration:underline). Log says, email sending is successful however email didn’t triggered.
Used code is,
trigger ExampleTrigger on Contact (after insert, after delete) {
    if (Trigger.isInsert) {
        Integer recordCount = Trigger.New.size();
        // Call a utility method from another class
        EmailManager.sendMail(xyz@zax.com', 'Trailhead Trigger Tutorial', 
                    recordCount + ' contact(s) were inserted.');
    }
    else if (Trigger.isDelete) {
        // Process after delete
    }
}
public class EmailManager {
    // Public method
    public static void sendMail(String address, String subject, String body) {
        // Create an email message object
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {address};
        mail.setToAddresses(toAddresses);
        mail.setSubject(subject);
        mail.setPlainTextBody(body);
        // Pass this email message to the built-in sendEmail method
        // of the Messaging class
        Messaging.SendEmailResult[] results = Messaging.sendEmail(
                                 new Messaging.SingleEmailMessage[] { mail });
       
        // Call a helper method to inspect the returned results
        inspectResults(results);
    }
   
    // Helper method
    private static Boolean inspectResults(Messaging.SendEmailResult[] results) {
        Boolean sendResult = true;
       
        // sendEmail returns an array of result objects.
        // Iterate through the list to inspect results.
        // In this class, the methods send only one email,
        // so we should have only one result.
        for (Messaging.SendEmailResult res : results) {
            if (res.isSuccess()) {
                System.debug('Email sent successfully');
            }
            else {
                sendResult = false;
                System.debug('The following errors occurred: ' + res.getErrors());                
            }
        }
       System.debug('sendResult =' + sendResult);
        return sendResult;
    }
}

In Setup->Deliverabilty- > All Emails. Still not triggering the email.



 
ShirishaShirisha (Salesforce Developers) 
Hi Kalaivani,

I can see that you have used the email address as "xyz@zax.com".Can you please double check,if this is valid emai address.Otherwise,I would suggest you to try with the different email address.

Also,if you have any issues with the Trailhead the please feel free to reach out to the Trailhead team using the below link:https://trailhead.salesforce.com/help

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
Ryan OlsenRyan Olsen
I'm running into the same issue. @Kalaivani did you ever figure this out?