You need to sign in to do that
Don't have an account?

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.
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.
All Answers
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;
}
}
{
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) ;"