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
Stephen02Stephen02 

Formula in Email Templates

Hello - I am attempting to enter a formula into a Salesforce Email template.
The requirement is this: If a field (e.g. Case.Send_WUPSIL_Letters__c) equals a specific value (e.g. Acknowledge), then I want to display a text message (e.g. We expect to have a response to you within the next 24 hours.

The below formula is what I have thus far, but I cannot get the text to return in the email template.

Thank you for contacting us. {! IF(Case.Send_WUPSIL_Letters__c=Acknowledge,"We expect to have a response to you within the next 24 hours")}
Best Answer chosen by Stephen02
Parker EdelmannParker Edelmann
I don't know much about formulas in email templates, but it looks like a syntax error if you can use a formula in the first place. I think it depends on how/where you're using it. If the field in question is a picklist, use this formula:
{! IF(ISPICKVAL(Case.Send_WUPSIL_Letters__c, "Acknowledge"),"We expect to have a response to you within the next 24 hours", "some other text")}
If it is a text field, then use this:
{! IF(Case.Send_WUPSIL_Letters__c, "Acknowledge","We expect to have a response to you within the next 24 hours", "some other text")}

The error was that you did not provide an "else" result, the value it uses if the record doesn't meet criteria, making the formula invalid.

If you want to evaluate multiple values easily, picklist or not, you can use this:

{! CASE(Case.Send_WUPSIL_Letters__c,
                                                             "Acknowledge", "We expect to have a response to you within the next 24 hours",
                                                             "Value2", "Result2",
                                                             // and so on and so forth
                                                             "else result")

Another thing that you may or may not need to do, is put {! } around the fields. I don't know if that's necessary or not, but you could try that if errors persist. Let me know if this helps you.

Thanks,
Parker

All Answers

Parker EdelmannParker Edelmann
I don't know much about formulas in email templates, but it looks like a syntax error if you can use a formula in the first place. I think it depends on how/where you're using it. If the field in question is a picklist, use this formula:
{! IF(ISPICKVAL(Case.Send_WUPSIL_Letters__c, "Acknowledge"),"We expect to have a response to you within the next 24 hours", "some other text")}
If it is a text field, then use this:
{! IF(Case.Send_WUPSIL_Letters__c, "Acknowledge","We expect to have a response to you within the next 24 hours", "some other text")}

The error was that you did not provide an "else" result, the value it uses if the record doesn't meet criteria, making the formula invalid.

If you want to evaluate multiple values easily, picklist or not, you can use this:

{! CASE(Case.Send_WUPSIL_Letters__c,
                                                             "Acknowledge", "We expect to have a response to you within the next 24 hours",
                                                             "Value2", "Result2",
                                                             // and so on and so forth
                                                             "else result")

Another thing that you may or may not need to do, is put {! } around the fields. I don't know if that's necessary or not, but you could try that if errors persist. Let me know if this helps you.

Thanks,
Parker
This was selected as the best answer
Stephen02Stephen02
Here's the answer. The below is saying that if the value in the Picklist, for the case field called ServiceLetters, that is chosen by the user is called Help, then display the text in the email template that says "This text will appear".  If it is not chosen, then do not show.

{!IF(ISPICKVAL(Case.ServiceLetters__c,"Help"),"This text will appear","NULL")}
Parker EdelmannParker Edelmann
You'll need to take the quotes off of "NULL". If you don't it will display NULL instead of actually being null. Glad my previous answer helped you.
Thanks for marking it as best.

Regards,
Parker