[SalesForce] Access parent object fields in VisualForce email template subject

I'm trying to display a parent field value in the subject line of a VisualForce email template and I'm running into problems. The use case is that we're going to fire an email alert that is based on a workflow rule on the child object.

Here's what I've got:

Parent object: Case

Parent object field: Case Number

Child object: n2de__Distribution_log__c

And here's how I've started, but I'm running into an error when saving. What am I missing?

<messaging:emailTemplate subject="Alert: 25 Minutes Before {!relatedTo.Case__r.CaseNumber} Misses Target" recipientType="User" relatedToType="n2de__Distribution_log__c">
<messaging:plainTextEmailBody >
Congratulations!
This is your new Visualforce Email Template.
</messaging:plainTextEmailBody>
</messaging:emailTemplate>

The error text is:

Error: Invalid field Case__r for SObject n2de__Distribution_log__c

Best Answer

I spun up Distribution Engine on my Developer instance, and it looks like the field you want is actually n2de__Case__r.

Try {!relatedTo.n2de__Case__r.CaseNumber}

Related Topic