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
Mohsin WadeeMohsin Wadee 

Conference Management App - Creating an Apex class

I created the class - which works when testing it through Debug > Open Execute Anonymous Window , but when verifying this step I get this error:

Step not yet complete... here's what's wrong: 
There was an unexpected error in your org which is preventing this assessment check from completing: System.EmailException: SendEmail failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Either the plain text body or html body must be supplied.: [] 
Note: you may run into errors if you've skipped previous steps.
Best Answer chosen by Mohsin Wadee
Mohsin WadeeMohsin Wadee
Ok, don't ask me how or why, logged in today - did not change a thing - and the tutorial now verified. Go figure.

All Answers

Mohsin WadeeMohsin Wadee
Here's the entire class (I preserved the other methods from a previous Trailhead module, the method in question here is the first one - sendMail):

public with sharing class EmailManager 
{
    public static void sendMail(String address, String subject, String body)
    {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] { address };
        mail.setToAddresses(toAddresses);
        mail.setSubject(subject);
        mail.setPlainTextBody(body);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }
    
    // Public method.
    public static void sendEmail(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);
    }
    
    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 case, the methods send only one email,
        // so we should only have 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());
            }
        }
            
        return sendResult;
    }
}
Lars NielsenLars Nielsen
Let's add a System.Debug right when you come into the method so we can assure that the calling method is not passing in a blank or null value
 
public static void sendMail(String address, String subject, String body)
    {
     System.Debug('*** subject = ' + subject + ' ****');
     System.Debug('*** body = ' + body+ ' ****');

 
Mohsin WadeeMohsin Wadee
Nah, tried that and it succeeded when I ran a test. What's worrying is that the error log for the verify test indicates it's using version 30 of the API.
Lars NielsenLars Nielsen
Okay, well - good on you for trying that already. How are you executing? From Eclipse or Developer Console? Hang on, I'm going to copy the class into my test org and try to call the method with version 29, 30...
Lars NielsenLars Nielsen
I can confirm the code works on 29,30-34 just fine. This is a little strange
Mohsin WadeeMohsin Wadee
Ok, don't ask me how or why, logged in today - did not change a thing - and the tutorial now verified. Go figure.
This was selected as the best answer
Anushka BansalAnushka Bansal
public with sharing class EmailManager 
{
    public static void sendMail(String address, String subject, String body)
    {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] { address };
        mail.setToAddresses(toAddresses);
        mail.setSubject(subject);
        mail.setPlainTextBody(body);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }

in the above code .. line 3  we have created a new instance of the class Messaging.SingleEmailMessage ..  why in the last line we are again using the keyword new .. why cant we simply write it as ​"Messaging.sendEmail(mail) ;"
 
Marek Smerak (TH)Marek Smerak (TH)
Have the same issue... Hopefully it will work tomorrow....
David Thompson 24David Thompson 24
Same here.  The method worked when I called it from the Confirmation Email trigger in a later step but I still get the "Challenge not complete" message.
Al PlateAl Plate
Same here.  Runs fine from Execute Anonymous window, but not when called for challenge verification.  I added debug statements and checked the log after attempting to verify and I see that subject, address, and body are all null.  Looks like a problem with the verification process.
Emma RosenfeldEmma Rosenfeld
I had the same problem.  I switched the API version of the Email Manager class down to 35 and verification of this step was successful.
Al PlateAl Plate
That also got me past the challenge.  Thank you Emma!
Marek Smerak (TH)Marek Smerak (TH)
Thank you Emma! Swithching API version helped me and also colleague of mine. Emma's answer should be marked as best answer ;).
William Parsons 4William Parsons 4
Thank you Emma!
Heidi KingHeidi King
Wow - that worked for me as well. Thank you Emma!!