1

I am using MassEmailMessage in APEX and I am trying to manipulate the body of the mass email message. I have successfully done this in a SingleEmailMessage. Here is my code:

EmailTemplate emailTemplate = [SELECT Id, Subject, HtmlValue, Body FROM EmailTemplate WHERE Id =: '00Xm0000000QEX5'];
String subject = 'Hello';
String htmlBody = emailTemplate.HtmlValue;
htmlBody = htmlBody.replace('{!PNAME}, c.FirstName);

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

mail.setReplyTo(fromaddress);
mail.setSenderDisplayName(fromaddress);
mail.setTargetObjectId(objId);
mail.setSaveAsActivity(true);
mail.setSubject(subject);
mail.setHtmlBody(htmlBody);

So when using MassEmailMessage, I don't have these methods at my disposal, so I am wondering if I can do something similar somehow. Thanks in advance!

1 Answer 1

1

Mass mail requires an EmailTemplate. Indentical to the way the UI works, your only option is to send the email verbatim without modification. To be able to specify a body, you can only use the single email format.

3
  • I will need to send up to 750 emails sometimes - any ideas how I can achieve this with SingleEmailMessage? Tia.
    – user8737
    Commented Jun 23, 2014 at 6:57
  • You'll probably need to use a batch class to properly send out that quantity of emails. You can trigger the batch class from another source, like a Visualforce page, executeAnonymous call, or a trigger.
    – sfdcfox
    Commented Jun 23, 2014 at 13:28
  • I now split up my emails into batches of 10 and send them out as single email messages. this works fine now. tks
    – user8737
    Commented Jun 24, 2014 at 8:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .