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
Debendra Ray 8Debendra Ray 8 

"common.apex.methods.MessagingStaticMethods$EmailExecutionException: SendEmail failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Either the plain text body or html body must be supplied:

Hi,
I'm getting following error while trying to run a scheduled job in the Production  :
"common.apex.methods.MessagingStaticMethods$EmailExecutionException: SendEmail failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Either the plain text body or html body must be supplied:

This code worked fine in the Sandbox.

Any suggestion towards circumventing this problem will be much appreciated.

Thanks & Regards,

Debendra
 
Raj VakatiRaj Vakati
Hi Devendra  ,

To send Email from Apex your code should contain plain text body or HTML body as shown below.   .  I believe your scheduled job is not able to set either setHTMLBody  or setPlainTextBody properly . I mean its setting with NULL values .Please make sure you are handling null values properly. 

 
List<Messaging.SingleEmailMessage> lstSingleEmailMessage = new List<Messaging.SingleEmailMessage>();
for (Account a : acc) {
    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
    email.setSubject('New Account Created!');
    email.setToAddresses(toAddresses);
    email.setHTMLBody('The account: ' + a.Name + ' was added to the system!');
    lstSingleEmailMessage.add(email);    
}
Messaging.SendEmailResult[] r = Messaging.sendEmail(lstSingleEmailMessage);