Adding conditional logic (IF, THEN) in Salesforce HTML email templates

conditionalemailemail-templatehtmlif

I'm struggling with adding IF, THEN conidition to my HTML Classic Email template and hoping someone can help.

I am trying to say if Cohort Owner's name is 'X', then post the X link, if Cohort Owner's name is 'Y', then post the Y link and if Cohort Owner's name is 'Z' then paste the Z link.

This is the statement I am using in SF that is not outputting what I'd like

{!IF({!Cohorts__c.OwnerFirstName} = "Bob", "Boblink", " ")}
{!IF({!Cohorts__c.OwnerFirstName} = "Tim", "Timlink", " ")}
{!IF({!Cohorts__c.OwnerFirstName} = "Anna", "Annalink", " ")}

This is the output it gives me when I send an email.

 = "Bob", "Boblink", " ")} = "Tim", "Timlink", " ")} = "Anna", "Annalink", " ")}

I'd like the output to be dependent on Cohort Owner and have the output as, i.e Here is.. Annalink (if Cohort Owner is Anna)

Any suggestions?

Best Answer

Merge fields start with {! and end with }. You do not use {! or } within the merge field. In addition, you can use a CASE statement, which is easier to read.

{!CASE(Cohorts__c.OwnerFirstName,
  "Bob", "Boblink",
  "Tim", "Timlink",
  "Anna", "Annalink",
  "")}

Or, if you prefer the IF statements, you can nest them together:

{!IF(Cohorts__c.OwnerFirstName = "Bob", "Boblink",
IF(Cohorts__c.OwnerFirstName = "Tim", "Timlink",
IF(Cohorts__c.OwnerFirstName = "Anna", "Annalink", " ")))}
Related Topic