0

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

1

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".

4
  • Thank your help contact object working fine but custom object not working please hep me
    – Divya
    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
    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
    Nov 12, 2020 at 2:08
  • @cropredy It should work, actually. If not, might be worth reporting to SF as a bug.
    – sfdcfox
    Nov 12, 2020 at 2:59
1

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.

{!IF(NOT(ISBLANK(test__c.MaxBath__c)),test__c.MaxBath__c,NULL)}
1
  • till now not completed my requirement please hepl me
    – Divya
    Mar 1, 2017 at 9:29
0

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:

!IF(NOT(ISBLANK(Contact.FirstName)),Contact.FirstName,"Friend")}

1
  • 1
    Please don't add "thank you" as an answer. Instead, vote up the answers that you find helpful. - From Review
    – identigral
    Jun 9, 2022 at 0:35

You must log in to answer this question.

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