+ Start a Discussion
Syed Aswan 5Syed Aswan 5 

If condition in email template

I'm using the following statement in custom email template:
{!IF({!Battle_Station__c.Project_Status__c}="Green","Green","Not Green")}

It giving me an output like this:
="Green","Green","Not Green")}

Can somebody pointout what might be the reason?
Thanks in advance.
Chiel de Graaf.Chiel de Graaf.
Hi Syed,

Try {!IF(Battle_Station__c.Project_Status__c="Green","Green","Not Green")}

I guess this should work
Syed Aswan 5Syed Aswan 5
Hello, Chiel.
Thanks for the reply.

I tried that above snippet, but it gives me nothing.
cloudSavvyProgcloudSavvyProg
Hi Syed,

What type of email template are you using for this purpose? Text or Visualforce or HTML
Did you try testing it as follows:
User-added image

Click on the button Send Test and Verify Merge Feilds as shown in above image.

Select a test record from the lookup (in your case Battle station record). Click OK.

Then check is your results  are as intended.

Hope this helps.

Regards,
CloudSavvyProg
Syed Aswan 5Syed Aswan 5
Hello, cloudSavvyProg.
Thanks for the reply.

I tried the same. still I got no output.
cloudSavvyProgcloudSavvyProg
Hi Syed,

What type of email template are you using for this purpose? Text or Visualforce or HTML

Can you post the screen shots please?

Regards,
CloudSavvyProg
Chiel de Graaf.Chiel de Graaf.
Hi Syed,

Try the following :
 
{!IF("{!Battle_Station__c.Project_Status__c}"="Green","Green","Not Green")}

 
Anthony Cioffi 6Anthony Cioffi 6
hi Chiel, how does this work? I try this and i get the opposite result - eg if my value of Battle Station is Green, it's returning Not Green. Please let me know?
Chiel de Graaf.Chiel de Graaf.
Hi Anthony, 

Could you post a snippet of your code.
Anthony Cioffi 6Anthony Cioffi 6
Sure I'll post when I get into the office. The problem seems to be with the salesforce custom html template type. The template is being triggered via email alert on an opportunity. Trying to evaluate an if statement doesn't return any result when tested; the closest if your suggestion to use quotes around each part of the equation, but then the if statement returns false incorrectly. So if I pretend to use your example that battle station is green, it returns not green when it evaluates in my test. Any ideas? Ty
Anthony Cioffi 6Anthony Cioffi 6
So in my custom html template, when I test the template,

this is my language field: {!Account.Language__c} which evaluates to English or French.
I tested your code as above as follows:
 
{!IF("{!Account.Language__c}"="French","isfrench","notfrench")}

and tested this variation too:
{!IF("{!Account.Language__c}"=="French","isfrench","notfrench")}

I tested with an account with French language, and it evaluates to "notfrench" which makes me believe that it is not actually working.

my full original code is this, and when tested, both IF statements return blanks.
<!DOCTYPE html>
<html>
<head>
<title>Submit a Review</title>
</head>
<body>
<script type="application/json">
{
    "recipientEmail": "{!Account.Merchant_Contact_Email__c}",
    "recipientName": "{!Account.Merchant_First_Name__c}",
    "referenceId": "{!Account.Merchant_Contact_Email__c}",
    "locale": "{!If(Account.Language__c == 'French','fr-FR','en-CA')}",
    "templateId": "{!If(Account.Language__c == 'French','template1','template2')}"
}
</script>
</body>
</html>



Please advise.
Chiel de Graaf.Chiel de Graaf.
Hi Anthony,

I took a look at my resolution of last year and applied it to your code.

The following should work:
 
{!IF(Account.Language__c ="French","isfrench","notfrench")}

Hope this does the trick.