function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
huskerwendyhuskerwendy 

IF Statement in Email Template not working with url link

I have an email template that is using an HTML letterhead. I added an if statement that is working but when I try to add a URL link to the conditional statement, it breaks.

 

This statement is working:

{!IF(Contact.Industry__c="Printers","Sign up for", NULL)}

 

When I try to add the URL, it won't display anthing. I've tried adding it multiple ways.

 

I tried adding the url link using the formatting controls at the top fo the page but it won't display anything when I select the template:

{!IF(Contact.Industry__c="Printers","Sign up for using format link", NULL)}

 

I've also tried adding HTML code but th doesn't display anything either.

 

{!IF(Contact.Industry__c="Printers",<a href="google.com">Sign Up for</a>, NULL)}

 

Any help would be appreciated.

Thanks,

Wendy

 



 

Rahul SharmaRahul Sharma

Hi Wendy,

Have you tried this:

{!IF(Contact.Industry__c="Printers",'<a href="google.com">Sign Up for</a>', NULL)}

 

huskerwendyhuskerwendy

Hi Rahul,

 

Thanks for the response. I tried that, but it just prints out everything between the single quotes on the template instead of making it a link. Like this:

 

<a href="google.com">Sign up for - forum</ a>



Any other ideas?

@ImJohnMDaniel@ImJohnMDaniel

Wendy,


If this is an HTML based email (i.e. <messaging:htmlEmailBody>? ), you might try a different approach.  Instead of trying to diisplay or not display the link, focus on the CSS display tag.

 

Your code was ....

 

{!IF(Contact.Industry__c="Printers",<a href="google.com">Sign Up for</a>, NULL)}??

 

Try instead .....

 

<apex:outputLink value="http://google.com" style="{! IF(Contact.Industry='Printers','','display:none;') }">Sign Up for</apex:outputLink>

 

The approach achieves the desired result but by working with the CSS instead.  If the contact's industry is not printers, then the style will equal "display:none;" and thus hide the entire link.

 

Also depending on how you setup the email template, you may need to replace the word "Contact" with "recipient" or "relatedTo".

 

Hope this helps.

 

Cheers,

 

John

 

huskerwendyhuskerwendy

Hi John,

 

Thanks for the suggestion. It's not an HTML based email but is using an HTML letterhead. I ended up putting the URL in plain text and will rely on email clients to convert it to a link. 

 

Wendy

Jade Fischer 24Jade Fischer 24

We had this same issue and could only find 1 source with the correct answer.  You need to concatenate the string for it to work.  The IF function will not recongnize the merge fields.  This needs a Salesforce Idea created for this because it isn't very intuitive.  Here is an example:

{!IF(Account.Name == 'John Doe','<a href=" ' & Account.Link & ' ">Account Record</a>','')}

The merge field is the Account.Link and you don't use the {!SomeObject.field} format that you usual copy from the field merge field search box above you just need to use dot notation.