I have a custom field MaxBath__c, and would like it rendered (viewable) if it is not empty otherwise don't make it viewable. How to write if conditions in below email code to achieve that?

{!test__c.MaxBath__c} bath,{!test__c.Type__c} 
for {!test__c.Rent_Min__c} per month located at 
{!test__c.Cities__c} {!test__c.State__c},{!test__c.ZipsFinal__c}

3 Answers 3


Yes, you can use most of the formula methods you'd use in Visualforce, formula fields, etc. Here's one way you could write the first part:

{!IF(NOT(ISBLANK(Test__c.MaxBath__c)),Test__c.MaxBath__c&' bath,','')}

You could also use a Visualforce template instead, which is longer, but I feel is more legible:

<apex:outputText rendered="{!NOT(ISBLANK(relatedTo.MaxBath__c))}" 
     value="{!relatedTo.MaxBath__c}&' bath," />

Be sure to test your templates before you use them by clicking "Send Test and Verify Merge Fields".

  • Thank your help contact object working fine but custom object not working please hep me
    – Divya
    Commented Feb 28, 2017 at 14:34
  • @sfdcfox can you please check the answer. Its not working. I checked with it and also please go through salesforce.stackexchange.com/questions/162567/…
    – KS Kumaar
    Commented Mar 1, 2017 at 11:15
  • I don't think IF expressions work if the comparand is other than a text field; e.g. {!IF(Contact.HasOptedOutOfEmail,'has opted out','has not opted out')} always returns false regardless of the actual value of the checkbox. Similar issue for number fields; did not test dates
    – cropredy
    Commented Nov 12, 2020 at 2:08
  • @cropredy It should work, actually. If not, might be worth reporting to SF as a bug.
    – sfdcfox
    Commented Nov 12, 2020 at 2:59

Assuming you want to print max bath when max bath field on test object is not blank,below code should work in your HTML template.

  • till now not completed my requirement please hepl me
    – Divya
    Commented Mar 1, 2017 at 9:29

If helpful for latecomers, @Samir solution worked for me in a like situation to if there's a name, display 'Dear Name' and if there's not, display 'Dear Friend' and it looks like this:



You must log in to answer this question.

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