Emails make the world go round. Well at least they make my inbox round (digital fat joke). Experienced users and admins know you can send emails from Salesforce completely ad hoc or by using email templates.
Email templates support merge fields which lets you place data from your Salesforce records directly into the email you’re sending. This is a great way for sending reminders to users, updates to managers, or notifications to clients. I’ve seen email templates used to send links to customer satisfaction surveys and even quotes & proposals.
With merge fields, Email templates in Salesforce can be very useful. With a little extra work they can also be amazingly flexible.
Adding Flexibility
Most email templates I’ve seen people create are fairly standard. They use the merge fields. If you’ve created a template, you’re familiar with this. There’s a dropdown for the object, the field and Salesforce will provide with the merge field text. It looks like “{!Opportunity.Amount}” without the double quotes.
This is all fine and dandy. It lets us put values of fields onto our email template. Did you know you can also use this to add formulas?
For example, we’re sending an email and if the Type of the Opportunity amount is greater than five thousand we want to say “Great” otherwise say “Okay.”
Our options:
- We can create 2 email templates, one for “Great” and one for “Okay.” Then create two workflow rules that will determine if the Amount is greater than 5000 and send the appropriate email.
- We can use formulas! {!if(Opportunity.Amount>5000,”Great”,”Okay”)}
Email templates will support most of the same formulas you’ll see when you are creating a Field Formula. Some of my favorite formulas that I use in Email templates include:
- IF
- CONTAINS
- CASE
- TEXT
Using formulas are fairly easy. Anything between “{!” and “}” will be resolved. This includes formulas and merge fields.
So Do this: {!IF(CONTAINS(Opportunity.NextStep,”Notify”),”Notify User”,”Don’t Notify User”)}
Not this: {!IF(CONTAINS({!Opportunity.NextStep},”Notify”),”Notify User”,”Don’t Notify User”)}
Some Gotchas
I will say that formulas within email templates can be somewhat temperamental. Recently I had a formula that looked 100% the same, but 1 resolved properly and the other didn’t. Sometimes it’s due to a copy/paste issues. Single quotes and double quotes may LOOK the same, but actually be treated differently.
So some suggestions when you’re using formulas:
- Don’t copy and paste. I know it’s a pain, but copy and pasting parts of your formula will cause things to not work. Hand type it all out… carefully.
- Decide if you should use a Formula in an Email Template or just create a Formula Field. Is this something you’re going to use over and over again? Across multiple templates?
- Try to avoid spaces. I’m still trying to figure this one out, but I had some formulas that were very long and wrapped on two lines. Those would fail to resolve, while similar formulas that didn’t wrap resolved just fine.
I thought images didn’t do this justice. At the same time, this topic is too short for a full Wizard’s Apprentice episode. So introducing, Wizard’s Apprentice Mini Spells!
These will be shorter videos on a variety of topics. Enjoy!