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
Ido Greenbaum 10Ido Greenbaum 10 

Custom Email Template - conditional output including merge field

I am trying to include a conditional logic in my custom Email Template, which includes merge fields.
When I include the following formula in my template:
<br />• Case #: {!IF(Case.RecordType ="Enterprise", {!Case.CaseNumber}, "not enterprise")}

The output in my email template looks as follows:
Case #: , "not enterprise")}

And when I edit the Email Template again, I can see that my code had changed to the following:
<br />• Case #: {!NullValue(IF(Case.RecordType ="Enterprise", "{!Case.CaseNumber")}, "not enterprise")}

Why is that?
Best Answer chosen by Ido Greenbaum 10
Alain CabonAlain Cabon
Hi,
  • You can use both " and ' (double and simple quotes) in a formula.
  • The concatenation is done with the operator &
  • if the expression is enclosed with simple quotes, use double quotes inside the enclosed expression (and vice-versa)
https://help.salesforce.com/articleView?id=customize_functions_a_h.htm&language=en&type=0

Given these three rules, you can write any expression as you want:

{!IF (Case.RecordType="Enterprise", Case.CaseNumber,
'<a href="https://portal.my-company.com/' & Case.CaseId18__c & '"  target="_blank">' & Case.CaseNumber & "," & Case.Subject & "</a>"  ) }

Best regards
Alain

All Answers

Alain CabonAlain Cabon
Hi,

Your problem is probably solved yet but you don't need to reuse {! } in the body of a formula.
 
<br />• Case #: {!IF(Case.RecordType ="Enterprise",Case.CaseNumber, "not enterprise")}
  1. {!Case.RecordType} and {!Case.CaseNumber}: you can verify the value of the recordtype alone (outside the formula) inside your emain template. Is it well resolved? exact value "Enterprise" ?  Sometimes we have to use : 
  2. What kind of email template is it ? 
User-added image

Custom (without using Lettherhead) ?

Regards
Alain
 
Alain CabonAlain Cabon
You can verify the value of the recordtype alone (outside the formula) inside your email template.
Is it well resolved? exact value "Enterprise" ?  Sometimes we have to use other values for the recordtypes.
(typos)
Regards
Ido Greenbaum 10Ido Greenbaum 10
Thank you for the assistsance Alain. 

It appears that the merge field is working properly as you've guided: 
<br />• Case #: {!IF(Case.RecordType ="Enterprise",Case.CaseNumber, "not enterprise")}

I have a follow up question - how can I pass an HTML 'href' element as an argument in the formula? I am trying the following without any luck:
{!IF
(Case.RecordType="Enterprise", Case.CaseNumber, 
 (<a href="https://portal.my-company.com/Case.CaseId18__c" target="_blank">Case.CaseNumber, Case.Subject</a>
  )
 )
}

 
Alain CabonAlain Cabon
Hi,
  • You can use both " and ' (double and simple quotes) in a formula.
  • The concatenation is done with the operator &
  • if the expression is enclosed with simple quotes, use double quotes inside the enclosed expression (and vice-versa)
https://help.salesforce.com/articleView?id=customize_functions_a_h.htm&language=en&type=0

Given these three rules, you can write any expression as you want:

{!IF (Case.RecordType="Enterprise", Case.CaseNumber,
'<a href="https://portal.my-company.com/' & Case.CaseId18__c & '"  target="_blank">' & Case.CaseNumber & "," & Case.Subject & "</a>"  ) }

Best regards
Alain
This was selected as the best answer
Ido Greenbaum 10Ido Greenbaum 10
Thank you Alain. Works perfectly.
Ben Rosenthal 3Ben Rosenthal 3
I'm trying to do something similar in a custom email template. We want to conditionally include a notification in daily emails to service volunteers if their driver's license has expired or will expire soon.

Neither of the formulas below is printing any output. Drivers_License_Expiration__c is a Date field. DriversLicenseExpired__c is a formula (text) field that compares the former to TODAY() and either reads "Expired" or "Active."
 
License Status: {! IF( DriversLicenseExpired__c = "Expired", "Your driver’s license has expired. Please make sure to renew and contact us with the new expiration date.", "Your driver’s license is still valid." )}
 
License Status: {! IF( TODAY() > Drivers_License_Expiration__c , "Your driver’s license has expired. Please make sure to renew and contact us with the new expiration date.", "Your driver’s license is still valid." )}

What am I missing?
Alo SenAlo Sen
Try adding the Object Name.Drivers_License_Expiration__c.
Priya ParabPriya Parab
I am trying to concatenate merge field with Text in IF condition
e.g. {!IF(ISPICKVAL(Opportunity.Sales_Channel__c,"Inbound Web"),'To continue your order login to your online account','You can call our Customer Service Team to continue your order, all you need is your reference number : '&Opportunity.Id)}
But the text isn't displaying if I use .&Opportunity.Id. Without &Opportunity.Id the text is displaying correctly.
Can any one help me out in this.
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.