You need to sign in to do that
Don't have an account?
Tim__m
Email Template getHtmlBody()
Using the SingleEmailMessage class I am trying to set the template Id, what Id, and target Id. I was disappointed when I tried to get the html body and found the body to be null. Is there a way to get an email template body after a merge with an sObject? Here is what I thought would work...
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setTargetObjectId(contactId); mail.setTemplateId(templateId); mail.setWhatId(caseId); System.debug('*********************'); System.debug(mail.getHtmlBody()); // getHtmlBody returns null :(
The Body of the template will be retrieved on the fly when you invoke the sendEmail method.
In the code you are just instructing that the SingleEmailMessage will use this particular templateId for sending out emails.
Setting the id will no way fetch the Body of Email.
As far as i know fetching the template body after merging with SObject cannot be done.
Thanks Imran,
I'm trying to get some answers from primer support and developer support but after they waste my time they will probable just say the same thing you just said.
is their any news on this ? can we retrive today the HTML ?
The basic idea is that you set up a save point, call sendEmail, get the rendered text, and then rollback the transaction. The email won't be sent because the transaction gets rolled back and you have your rendered text.