function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bozotheclownbozotheclown 

HTML Template Merge Fields - using related object fields

Hello.  I have an e-mail template that is used by a workflow e-mail alert.  The e-mail alert is based on the workorder__c field.  I also have a related object (via lookup relationship) called parts__c. 

 

I am able to display the workorder__c.workordername__c field values in e-mails created from this template.  However, I am getting blanks where I am trying to display parts__r.partname__c.

 

In short, is there any way to display data from related objects in an HTML template...or can you only display data from a specific object?

 

Hope this makes sense.  Thanks in advance.

phiberoptikphiberoptik

So the email template is based on the Workorder object or a different object?

phiberoptikphiberoptik

Ok, I believe I know your problem.

 

You are trying to independently include fields from a related object but without the relationship. Based on parts__r.partname__c, there is no reference to the workorder that the part is related to.

 

Instead of parts__r.partname__c, try workorder__r.parts__r.partname__c

bozotheclownbozotheclown

Thanks.  I appreciate the help.  Unfortunately, that did not work.  I have been doing some further searching and I saw a passing reference somewhere about problems with referencing related objects' values in HTML email templates. 

 

My workaround to this was to just create a formula field in the workorder object.  That way, all of the fields I need are in the workorder object.

 

Thanks for the suggestions though.

phiberoptikphiberoptik

Just my personal experience testing this out:

 

In my dev org, I have an object that has a lookup relationship to Accounts, called Bogus Test Object.

 

In an email template, for me to populate the name of the Bogus Test Object that is related to the Account that the email is being sent from, I have to use the merge field {!Account.Bogus_Test_Object__c}

 

But to your point, it appears that I cannot dig into the related objects fields. Youre right, it looks like formula fields are the solution.

SSKahlonSSKahlon
@phiberoptik, @bozotheclown

You cannot use cross object merge fields in an email template. This is currently not possible but might be on the roadmap.
Please refer to IdeaExchange: https://success.salesforce.com/ideaview?id=08730000000Brk7AAC
 
spielsspiels
Good afternoon! In case you're still looking for an answer to this issue, you CAN now use cross object fields in email templates with a 3rd party addin. It's pretty easy. You can find out more here: http://www.contactmonkey.com/blog/cross-object-fields-in-salesforce-email-templates-fixed

Happy merging!