'How to use an if-statement in SalesForce E-Mail Template
I'm trying to add a if-Statement to my E-Mailtemplate (Type: HTML). I used the following code:
{!if(Lead.LastName="", "1", "2")}
My Output is just nothing :/
Does anyone know how to do it right?
Solution 1:[1]
I believe the more complex logic like conditionally rendering data is not available in straightforward emails. IF, BLANKVALUE etc functions don't work, instead there's something similar to Dear {!Lead.LastName, 'Sir or Madam'} that's supposed to be fallback scenario if the field was empty.
If you're not too afraid - make a visualforce email template instead?
<messaging:emailTemplate subject="Hello StackOverflow" recipientType="User" relatedToType="Lead">
<messaging:HtmlEmailBody >
<p>Related To: {!relatedTo.Name}, {!relatedTo.LeadSource}</p>
<p>Recipient: {!recipient.Username}</p>
<p>{!IF(ISBLANK(relatedTo.LeadSource), '1', '2')}</p>
</messaging:HtmlEmailBody>
</messaging:emailTemplate>
Solution 2:[2]
Please use following Format, then it should work:
{!IF(Lead.LastName='','1','2')}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | eyescream |
| Solution 2 | ouflak |
