We have a set of email templates with letter head and images. We want to display a preview of the selected template so we query the EmailTemplate object, assign the htmlValue field value to a var that is shown on a VisualForce.  The var is shown in this way:

<apex:outputtext value=" {!templateBodyPreview}" escape="false" />

We replace the merge fields with the real values. The text is correctly shown and formatted but the images and the letter head are not shown.

Anybody has done this before? Any advice?

  • Are you using a custom VF component plus controller to provide a value for the merge field above? – cropredy Sep 5 '16 at 15:52
  • Yes, It's a VF component with a controller – Victor Garrido Matas Sep 6 '16 at 6:15

First principles here:

When editing a VF email template in the point-and-click editor, there are two possible preview 'modes"

  1. The 'default' mode - the one presented to you when you initially see the VF template as a 'detail' page. In this use case, the values of merge fields relatedTo and recipient are null. If using a custom component in the VF email template, then any arguments you pass from the outer template into the custom component's controller via apex:attributes that rely on {!relatedTo.xxx} or {!recipient.yyyy} will be null. The custom component controller needs to be able to handle null values in the setters.
  2. The Test Preview and Send Email mode - invoked when clicking the preview button. In this mode, you have to supply a record Id for both relatedTo and recipient and hence any attributes in the custom component that depend on those values should have non-null merge field values

If you have use case 1, then it is quite possible there's not enough information for the component's controller to resolve a value for merge field {!templateBodyPreview} and hence it displays as null.

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.