I was working with some colleagues this morning who had a requirement to send an email using the email template functionality, but wanted to access data from a grandchild object (so Parent Object–>Child Object–>Grandchild Object). At first glance the UI only allows you to select fields from the Parent or Child object, but fear not — you can supercharge your email template merge fields with just a little extra effort.


Take the example of a school which has an Enrollments object which is related to Classes via a Master Detail relationship. Classes have a similar relationship with Venues (a class has to be held somewhere), but an Enrollment really shouldn't have any sort of relationship with a Venue (thats the classes responsibility). To make things easier we may model this the Class-Venue relationship in another custom object, we could call ClassVenues:

With our newly discovered superpowers in the Email Template, we can easily traverse the new relationship to send our student all the details they need to make it to class right on time. The trick is writing the merge field yourself. You can use the Available Merge Field picklists as a start, but you have to manually add the grandchild relationship. For this example the following code works great:


Now if only I could get fix the 'dog ate my homework' problem 🙂

Get the latest Salesforce Developer blog posts and podcast episodes via Slack or RSS.

Add to Slack Subscribe to RSS