0

I have a VF email template and in apex I want to get it's content and will replace its merge fields. I am using below code but it gives null value.

EmailTemplate et = [select body,htmlvalue,templatetype from emailtemplate where id='00X60000004GK1SEAW'];
system.debug('body-'+et.Body); // gives me null
system.debug('html-'+et.htmlvalue); // gives me null
system.debug('html-'+et.templatetype); // gives me visualforce

Can anyone tell me how to get content of VF template here?

  • in order to get the content you need to set email messaging targetObjectId and setwhatId – Ratan Paul Jan 6 '16 at 6:21
  • @Ratan - I don't want to send any email. I just want to preview email content to the User. It works fine with HTML template but not with VF template. – doga Jan 6 '16 at 7:02
1

I can suggest a workaround like this:

Getting Email's Html body

Here, in this link, @Pieterjan Carly, didn't send actual email. However he used a feature of Salesforce, when we use SEND method, it automatically creates Email Body.

Now, Solution to your problem:

  1. Get EmailTemplate
  2. Set merge fields
  3. Send dummy mail and rollback it
  4. As of now,you got exact body, store it in a STRING
  5. Set that stored string on VF, so that you can show the EmailTemplate preview in VF
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.