You need to sign in to do that
Don't have an account?
Making Email Template Merge Fields Work
According to the Help documents, it should be possible to follow relationship chains to fill out mail merge fields (e.g. "Opportunity.Account.CreatedBy.Phone"). For my custom objects; however, I can only get them to work across a single relationship.
So, "{!NullValue(Answer__c.Response__c.Account__c.OwnerFirstName, "Account Manager")}," seems like it ought to work but it doesn't. (In my object model, Answer__c has a lookup relationship named "Response" to a Response__c, which has a lookup relationship "Account" to an Account).
The string "Answer__c.Response__c" works, but the string "Answer__c.Response__c.Account__c" does not either.
I see there is some 40 character limit on merge field names? 40 characters, REALLY???
I've tried removing the "__c" names, also using "__r" but no help. Does this feature actually work? Can someone help get me back on the right track?
Jeff
The Owner Name fields are not yet exposed via Merge Fields / Formula Fields.
Here are two Ideas promoting that feature:
http://ideas.salesforce.com/article/show/10095855/CrossObject_Formula_Fields_Be_able_to_insert_related_OWNER_data_into_a_formula_field
http://ideas.salesforce.com/article/show/10089647/Lookup_Formula_Fields
All Answers
What is the error message that you're seeing?
This code displays a value in my org:
<messaging:emailTemplate subject="Test" recipientType="Contact" relatedToType="Answer__c">
<messaging:plainTextEmailBody >
{!relatedTo.Response__r.Account__r.OwnerId}
</messaging:plainTextEmailBody>
</messaging:emailTemplate>
The component reference has some sample code:
https://na6.salesforce.com/apexpages/apexcomponents.apexp (click on the "usage" tab for the "messaging:emailTemplate" component)
Here are some more samples that might be useful:
http://wiki.apexdevnet.com/index.php/VisualForceEmailTemplates_sample
http://gokubi.com/archives/visualforce-email-templates
http://gokubi.com/archives/visual-force-email-templates-2
I created a Visualforce email template as below and it almost works. The only thing I cannot do is access the Account Owner's first name in the salutation. I can get the OwnerId, but that is not useful. Everything I have tried to traverse to the User raises an exception. Where are these legal fields specified? The merge field dropdown in the text template editor is wrong, the Force.com Standard API fields don't work.
I tried using "recipient.FirstName" which does work; however, it seems to be using the Answer's owner instead of the Account owner that I specified in the Email Alert. The plumbing here is not working the way I want it to.
Still Frustrated,
Jeff
<messaging:emailTemplate subject="Detractor Alert: Score={!relatedTo.Score__c}" recipientType="User" relatedToType="Answer__c">
<messaging:plainTextEmailBody >
Dear {!relatedTo.Response__r.Account__r.OwnerId}
This is an automated email about a new detractor incident. Please follow-up appropriately.
Date: {!relatedTo.Date__c}
Type: {!relatedTo.Question__r.Question_Type__c}
Product: {!relatedTo.Question__r.Product__r.Name}
Respondent: {!relatedTo.Response__r.Respondent__r.FirstName} {!relatedTo.Response__r.Respondent__r.LastName}
Score: {!relatedTo.Score__c}
Comments:
{!relatedTo.Answer_Text__c}
</messaging:plainTextEmailBody>
</messaging:emailTemplate>
The Owner Name fields are not yet exposed via Merge Fields / Formula Fields.
Here are two Ideas promoting that feature:
http://ideas.salesforce.com/article/show/10095855/CrossObject_Formula_Fields_Be_able_to_insert_related_OWNER_data_into_a_formula_field
http://ideas.salesforce.com/article/show/10089647/Lookup_Formula_Fields