• TechnoGeek61
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies

I have a batch Apex process that sends an email message to the contact for a case when some conditions are met via the Messaging.SingleEmailMessage class using an email template as follows:

 

        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        
        mail.setTemplateId(EMT.Id);
        mail.setUseSignature(false);
        mail.setBccAddresses(mailTo);
        mail.setReplyTo('support@XXXXXXXXX');
        mail.setTargetObjectId(myContact.Id);
        mail.setWhatId(myCase.Id);
        mail.setSaveAsActivity(false);

The code works exactly as I expect, but I also need the message that was sent out to show up in the Email related list of the case (so that we have a copy of the message that was sent attached to the case).

 

My initial plan was to also add an EmailMessage object to the case via "EmailMessage myEmailMsg = new EmailMessage();" call, but when it came to the TextBody field, I am not sure what I should use here since the message is created via a template.

 

Does anybody have any suggestions on how to have the outgoing message attached to the case?

 

Thanks!

 

Marc