function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Stéphane CLARETStéphane CLARET 

HTML tags "<" converted in "&gt;" when merging fields in visualforce email template

You can try with a very simple formula field with just IMAGE() like:

Contact.Avatar__c = "IMAGE("http://fr.pageondemand.com/emailing/signature_pictures/SCL.jpg", "SCL")"

and create a Visualforce Email Template with:

<messaging:emailTemplate subject="Test for merging HTML fields" recipientType="Contact" relatedToType="Contact">
<messaging:htmlEmailBody >
<html>
<br/>
This is when merging the field:<br/>
{!relatedTo.Avatar__c}<br/>
<br/>
This is when puting the HTML code directly in the template code:<br/>
<img src="http://fr.pageondemand.com/emailing/signature_pictures/SCL.jpg" alt="SCL" border="0"/>
</html>
</messaging:htmlEmailBody>
</messaging:emailTemplate>


Merge with any contact and see: the merged field is not interpreted as HTML.

If you look at it in an email, you will see that 

<img src="http://fr.pageondemand.com/emailing/signature_pictures/SCL.jpg" alt="SCL" border="0"/>

has been replaced by:

&lt;img src="http://fr.pageondemand.com/emailing/signature_pictures/SCL.jpg" alt="SCL" border="0"/&gt;

I didn't found any workarounds. I tyied of course <apex:outputText value="{!HTMLENCODE(relatedTo.Avatar__c)}" escape="false"/> with no better results.

I think this is a bug… but Salesforce Support sent me here "to be sure"…
Vatsal KothariVatsal Kothari
Hi Stephane,

What you can do is, create one more formula field(URL__c) with Text Return type and formula "http://fr.pageondemand.com/emailing/signature_pictures/SCL.jpg".

Now edit your Visualforce Email template with below code:

<messaging:emailTemplate subject="Test for merging HTML fields" recipientType="Contact" relatedToType="Contact">
<messaging:htmlEmailBody >
<html>
<br/>
This is when merging the field:<br/>
<img src="{!relatedTo.URL__c}" alt="SCL" border="0"/>
<br/>
This is when puting the HTML code directly in the template code:<br/>
<img src="http://fr.pageondemand.com/emailing/signature_pictures/SCL.jpg" alt="SCL" border="0"/>
</html>
</messaging:htmlEmailBody>
</messaging:emailTemplate>
If this solves your problem, kindly mark it as the best answer.

Thanks,
Vatsal

Stéphane CLARETStéphane CLARET
Hi Vatsal,

It worked. Thank you for that.

However, I have the exact same problem with Idea.Body and Idea.LastComment.CommentBody. And, I do not see how to use your workaround with these two fields. (I wish I could just turn off HTML field type for Ideas and their comments by once it is enalbed, we can not go back.

Any idea?

Thnaks.
Stéphane
Vatsal KothariVatsal Kothari
I have created new Visualforce Mail template  related to "Idea" Object and it worked for me.

<messaging:emailTemplate subject="test123" recipientType="User" relatedToType="Idea">
<messaging:plainTextEmailBody >
Congratulations!
This is your new Visualforce Email Template.
{!relatedTo.Body} 
{!relatedTo.LastComment.CommentBody}
</messaging:plainTextEmailBody>
</messaging:emailTemplate>
If this solves your problem, kindly mark it as the best answer.

Thanks,
Vatsal

Stéphane CLARETStéphane CLARET
No it does not.

This is the result:

Congratulations!
This is your new Visualforce Email Template.
When versions are created they need to include the pricing.
<div>
When PageOnDemand was opening for business, majority of users was expecting that prices could be imported. It made sens since users were also using an ERP or at least spreadsheets and didn&#39;t want to take any chances by keying the price values again in PageOnDemand.</div>
<div>
</div>
<div>
That was 8 years ago and PageOnDemand users are much more various now.</div>
<div>
</div>
<div>
We understand though that some users may prefer to key price values directly in PageOnDemand and therefore would expect to have an easy way to copy prices from a catalog to an other.</div>
<div>
</div>
<div>
We heard you and even more: we are considering to bring to PageOnDemand users a brand new feature to clone catalogs that would include of course the price list copy.</div>


More over, I need it to be HTML and not plainText. I tested it in HTML, this is the result:

Congratulations! This is your new Visualforce Email Template. When versions are created they need to include the pricing. <div> When PageOnDemand was opening for business, majority of users was expecting that prices could be imported. It made sens since users were also using an ERP or at least spreadsheets and didn&#39;t want to take any chances by keying the price values again in PageOnDemand.</div> <div>  </div> <div> That was 8 years ago and PageOnDemand users are much more various now.</div> <div>  </div> <div> We understand though that some users may prefer to key price values directly in PageOnDemand and therefore would expect to have an easy way to copy prices from a catalog to an other.</div> <div>  </div> <div> We heard you and even more: we are considering to bring to PageOnDemand users a brand new feature to clone catalogs that would include of course the price list copy.</div>

In the email, this is what we got:

<html>
Congratulations!
This is your new Visualforce Email Template.
When versions are created they need to include the pricing.
&lt;div&gt;
When PageOnDemand was opening for business, majority of users was expecting that prices could be imported. It made sens since users were also using an ERP or at least spreadsheets and didn&amp;#39;t want to take any chances by keying the price values again in PageOnDemand.&lt;/div&gt;
&lt;div&gt;
&nbsp;&lt;/div&gt;
&lt;div&gt;
That was 8 years ago and PageOnDemand users are much more various now.&lt;/div&gt;
&lt;div&gt;
&nbsp;&lt;/div&gt;
&lt;div&gt;
We understand though that some users may prefer to key price values directly in PageOnDemand and therefore would expect to have an easy way to copy prices from a catalog to an other.&lt;/div&gt;
&lt;div&gt;
&nbsp;&lt;/div&gt;
&lt;div&gt;
We heard you and even more: we are considering to bring to PageOnDemand users a brand new feature to clone catalogs that would include of course the price list copy.&lt;/div&gt;</html>


Thanks,
-Stéphane
Laurent DHAISNELaurent DHAISNE
Hi Stephane,

Sorry to reopen this matter, did you find any solution to solve this issue ?
Same problem here with < converted when apply merge fields 

Thank you
Laurent