1

I am trying to create an email template for my contact object, but I need to refer to some fields of related objects.

My set up is as follows:

Contact: Name, Email

Patient__c: Type

Disease__c: Name, Category

Patient__c and Disease__c are in a Master detail relationship, where Disease__c is the Master. Contact is a Lookup field in Patient__c.

I now need to send an email along the lines of:

Dear {!Contact.FirstName},

You were tested for disease: {!Contact__r.Patient__r.Disease__r.Name}.

I am not sure how to get that cross object merge field right. It would be great if someone could help.

Thanks in advance!

  • 1
    1) Are you using HTML or VF email templates? and (2) which object is the 'master' object for the email template? (for example, is the email template part of an email alert on Contact? or is the master object set via Apex Single EmailMessage? More details are needed here because in some use cases, the parent -> childlist relationship data is not available without using VF components/custom controllers. – cropredy Jun 17 '14 at 16:47
  • Do you want to include one "patient" in that email or all patient records for that one contact? How do you plan to fire this email - from Contact (I guess for all "patients"? or just one), from patient or what? – eyescream Jun 17 '14 at 19:46
  • Hello, I am using HTML as Visualforce cannot be used with massemailmessage in apex. Contact is the Master of the email template. The email is sent via an apex trigger using massemailmessage. I want to get all the patients that have a specific disease and then send a personalised email to all those patients. I hope this makes sense. Thanks! – user8737 Jun 19 '14 at 8:19
  • Any updates here? – Chirag Mehta Aug 27 '14 at 10:28
2

There is an Idea for this: use cross-object merge fields in email templates that, as of December 2015, is under consideration. Vote it up!

Since your schema is:

Contact          Disease
   |                |
   |                |
   |                v
   ---------->  Patient

OPTION 1

You will need to send the Email on Patient and where Patient has two custom formula fields:

Patient Contact Email - defined as Contact__r.email
Patient Disease - defined as Disease__r.name

OPTION 2

Create a new custom object called Email Proxy. Update that with all the fields you need to send the email (recipient (as field of type Email), disease name, patient name). Add a field called "Is ready to send". Point the template at the email proxy object

Use workflows or process builder to send the email (because "is ready to send" is true. Reset this field to false after workflow/process executes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.