How can I make a email template merge field conditional if it's a lookup field? - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Heather NeumannHeather Neumann 

How can I make a email template merge field conditional if it's a lookup field?

My Case object  has a field that requires a user to look up an Account and link it to the Case. Then, the user can look up the Contacts for the Account and link one of the Account Contacts with the Case. Standard stuff. However, the Contacts lookup field is not required. We often receive support requests from people who aren't set up as Contacts. So if we're working with a customer who isn't a Contact, we capture the customer's name, phone # and email address in some custom fields on the Case object. For any Case, we will have either a Contact (with a name, phone # and email address) or values in custom fields Submitted By Name, Submitted By Phone and Submitted By Email.

I am writing an email template to be used in responding to a case. I would like to merge in the Contact Name, and if there's no Contact linked to the case, I'd like to merge in the Submitted By Name instead. I have written the merge field as a function, like so:

Dear {!if(Case.Contact="", Case.SubmittedBy_Name__c,Case.Contact)}:

This works great if there's no Case Contact; the Submitted By Name drops into the message like a champ. However, if there is a Case Contact, the template pulls in a long nasty number instead of the Contact Name. (I assume this is the Contact's ID number, but I don't know for sure.)

I have also tried using BLANKVALUE and NULLVALUE functions instead of IF. No luck.

Any sugestions are appreciated!

 

Shashi KantharajShashi Kantharaj
You could create a custom formula field on the case object containing the contact name and use that
in your template.
Heather NeumannHeather Neumann
I worked it out by breaking it into two merge fields. It goes like this:

Dear {!Case.Contact}{!if(Case.Contact="",Case.SubmittedBy_Name__c,"")}:

This works because the Case.Contact field merges OK as long as it's not part of a formula or function. So if there's a Case Contact, the first merge field drops it in, and the second merge field evaluates to an empty string. If there's no Case Contact, the first merge field is empty, and the second merge field evaluates to the Submitted By Name.