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
Robert Wambold 10Robert Wambold 10 

!NOW() and HYPERLINK do not render correctly in Custom Email Template

Hello all,

I been struggling trying to get my Custom Email Template to display the current date/time using {!NOW()} and HyperLink to render.

When I so a Preview my email renders perfect. When I generate the email from Apex  {!NOW()} displays as "{!NOW()}" and Hyperlink as "HL_ENCODED_url_HL_OpenLink_HL__self_HL".

When I use an HTML Template I ge no output at all.

Any ideas?

Thank you!

Robert

 

Output from Preview

Output from APEX

 

SwethaSwetha (Salesforce Developers) 
HI Robert,
Does this happen only in Outlook or across other email clients like Gmail/yahoo etc too? Thanks
Robert Wambold 10Robert Wambold 10

Hello Swetha,

Same results in Gmail.

Could it be my APEX?

Regards,

Robert
 

 

 

SwethaSwetha (Salesforce Developers) 
HI Robert,
Apologies for the delay.
EDIT:
I tried the code snippet mentioned in 
https://salesforcescool.blogspot.com/2019/01/send-email-using-custom-email-template.html to test the Custom Email Template and noticed that

> when the Text-Only Email Content is left blank, the code throws a null exception. Looks like apex picks the content from "text-only content" 
>When you "Copy Text from HTML version", the merge fields are copied as plain text which is what it is reflecting in the received email too.
>These merge fields work as expected when the email is sent via"Send Test and verify merge fields"

As per the documentation, https://help.salesforce.com/articleView?id=sf.creating_custom_html_email_templates.htm&type=5 "If you use that same template to send email via the API or APEX, you must provide the text-only content"

I tried to update the apex code with something like 
 plainText = plainText.replace('System.now()','{!NOW()}'); but that doesn't help.

This seems to be a limitation with custom email templates. I recommend logging this as Idea on IdeaExchange so that the product development team can consider in coming releases.

If this information helps, please mark the answer best.Thank you