1

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?

2 Answers 2

3

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", " ")))}
4
  • Amazing, this worked like a charm. Definitely the CASE statement is easier to read and will be using that - thank you for introducing me to it :)
    – Samridhi
    Commented Nov 26, 2021 at 8:30
  • If I may ask a follow-up question - I'm trying to use it to display a particular hyperlink and thought this would work based on your suggestion. It just displays as blank as opposed to "this link" (hyperlinked to a specific link, i.e www.boblink.com if bob. Any thoughts? (Note the spacing between https:// and the link is just to post in the forum to show the code {!CASE(Cohorts__c.OwnerFirstName, "Bob", <a href="https:// boblink.com">this link </a>, "Tim", <a href="https:// timlink.com">this link </a>, "Anna", <a href="https:// annalink.com">this link </a>, "")}
    – Samridhi
    Commented Nov 26, 2021 at 9:16
  • @Samridhi You can use the HYPERLINK function to generate an appropriate link. {!HYPERLINK(CASE(Cohorts__c...), 'this link')} You can also do the HTML yourself, I'd recommend doing just the URL bit, as in <a href="{!CASE(...)}">this link</a>.
    – sfdcfox
    Commented Nov 26, 2021 at 15:34
  • Thaaank you - saved me so much hand banging time against a wall!
    – Samridhi
    Commented Nov 27, 2021 at 15:19
0

Another example with few merge fields in the hyperlink.

Scenario: If the Case Origin is Email, then expected URL is as below: URL: https://example.salesforce.com/emailOrigin?caseId=encryptedCaseRecordIdStoredInCase

If the Case Origin is ContactUsWebPage, then expected URL is as below: https://example.salesforce.com/contactUsWebPageOrigin?caseId=encryptedCaseRecordIdStoredInCase

Below is the sample code snippet that can be used in HTML Email Template in Salesforce:

<p>Please <a href="https://example.salesforce.com/{!CASE(Case.Origin,'Email','emailOrigin','ContactUsWebPage','contactUsWebPageOrigin','')}?caseId={!Case.Encrypted_Record_Id__c}" target="_blank">click here to view the Case</a>

Output:

If the Case Origin is Email: Please click here to view the Case

If the Case Origin is ContactUsWebPage: Please click here to view the Case

You must log in to answer this question.

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