You need to sign in to do that
Don't have an account?
Haseeb Ahmad 9
Error sending email - REQUIRED_FIELD_MISSING, Email body is required.: []
Hi Everyone,
Trying to send email from apex and receiving error:
System.EmailException: SendEmail failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Email body is required.: []
Apex Class:
Trying to send email from apex and receiving error:
System.EmailException: SendEmail failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Email body is required.: []
Apex Class:
public with sharing class EmailUtils { public static void sendEmail(List<String> toAddresses, String senderDisplayName, String subject, String body) { Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.settoAddresses(toAddresses); mail.setSenderDisplayName(senderDisplayName); mail.setSubject(subject); mail.setPlainTextBody(body); Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); }Test:
@isTest private class EmailUtilsTest { @isTest static void testEmailUtils() { Test.StartTest(); EmailUtils.sendEmail(new List<String>{'test@test.com'}, 'Unit Test Name', 'Unit Test X', 'Unit Test'); Integer invocations = Limits.getEmailInvocations(); Test.stopTest(); System.assertEquals(1, invocations, 'An email has not been sent'); }It has 100% code coverage but when I am trying to deploy in production getting that above error. please help, thank you.
I think there is no error in your code but When you actually execute it, The body must not be null or empty.
Try and find the reason why your mail body is Empty.
Thanks
A similar discussion is on https://salesforce.stackexchange.com/questions/283764/error-sending-email-required-field-missing-email-body-is-required
Adding to the above user's comment, your code would run successfully when executed in a developer console like
You need to ensure that the method below is getting all the needed parameters which in your case is missing the body
public static void sendEmail(List<String> toAddresses, String senderDisplayName, String subject, String body)
Related: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_email_outbound_single.htm
Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful.Thank you