How do I create a formula with merge fields for lightning email templates? - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Daniel RenfroDaniel Renfro 

How do I create a formula with merge fields for lightning email templates?

I'm trying to create a merge field using a formula in Lightning email templates. I know this was possible in Classic using this formula: 

{! IF( ISBLANK( Contact.Nickname__c), Contact.First_Name_Proper_Case__c, Contact.Nickname__c) }

That is exactly what I'm wanting to just in Lightning. I want the formula to check and see if there is a value in the Nickname field, if there is, use that. Otherwise, if the nickname field is empty it will pull the value from the First Name field. 

Does anyone have any suggestions on how to do this in Lightning? Thanks in advance!
Best Answer chosen by Daniel Renfro
Deepak AnandDeepak Anand
As far as I read, there is NO way to do this in the Lightning Email Templates. The HML(Handlebars Merge Language) doesn't support conditional statements at least now.

So I recommend that you create a Formula Field on the Contact with that exact same Formula and use it instead.

All Answers

Deepak AnandDeepak Anand
As far as I read, there is NO way to do this in the Lightning Email Templates. The HML(Handlebars Merge Language) doesn't support conditional statements at least now.

So I recommend that you create a Formula Field on the Contact with that exact same Formula and use it instead.
This was selected as the best answer
Daniel RenfroDaniel Renfro
Thanks for the help, Deepak! 
Rick UptonRick Upton
You can upvote the idea "Make merge fields conditional in an email template". In the meantime, I like Deepak's solution especially for greetings. I can use one custom greeting field for all email templates, and if I decide to change the format of the greeting (e.g. change Hello to Dear, change a comma to a colon, add the last name, etc.) I can do that in the forumla for one custom formula field and all of my email templates will be updated with the new greeting.
Hanna SandovalHanna Sandoval
Unfortunately we're maxed out on formula fields already on the Case object, so this is not a solution for us. Any other ideas?