I'm trying to add some logic to our templates but there doesn't seem to be much documentation about this topic.

The syntax I'm using is the following:

{!IF(QA_Ninjas__c.Entities_Agregados__c>0,"Entities agregados:  "+QA_Ninjas__c.Entities_Agregados__c+"<br/>","")}

I read somewhere that this only works for text and I'm using a number field here. Am I using the correct syntax or is there another way to get the same result? Currently nothing displays when I send the email.


1 Answer 1


It's doable but you won't like the answer. As far as I know there's no IF(). You can use NullValue (probably also BlankValue). So - to achieve what you're after you'd need to waste a formula field to store your ">0" logic.

Here's an Account-related HTML template I've just made:

{!Account.Name} : {!NullValue(Account.NumberOfEmployees, "(no data)")}

If wasting so many fields is not an option - consider making a Visualforce template. As your logic grows more complex you'll probably want to show/hide whole sections anyway (rendered attribute).

Couple other things that bit me in the past:

  1. Check the real body of template (with Eclipse IDE or by querying the the EmailTemplate table by Id) & if you're stuck - post here the relevant bit exactly as it is.
  2. What do you use to edit the template? Often the online editor tries to be helpful & injects <span>,<font>,<div> tags in all the wrong places, rendering your logic useless. MS Word is especially infamous for inserting this rubbish. Use a text editor (Notepad++?) and save directly via Eclipse, no copy-pasting.
  • +1 for the VF Email Template suggestion; it is super annoying that the formula merge fields don't work consistently across all email template types
    – cropredy
    Oct 10, 2017 at 14:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .