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
alex_from_75015alex_from_75015 

Email template and lookup field (and condition)

Hi

I have a object "proposal" with 2 lookup fields (not master relationship) : one for product and one for insurrance

What would be the syntax in "proposal" email template to call field from product / insurrance

 

I have tried many syntax but still empty : exemple for company field

{!Proposal__c.Company__c.Description__c}

{!Proposal__c.Company__r.Description__c}

{!Company__c.Description__c}

 

{!Proposal__c.Product__c.Description__c}

 

{!Proposal__c.Product__r.Description__c}

 

{!Product__c.Description__c}

 

Moreover is is possible to write in email template something like :

if (!Proposal__c.Type="xxx")

{

  • ezazeza
  • eazeaz
  • eeezaez

}

else

{

  • lml
  • lmlm
  • lmlm

}

Thanks for your help since I could not any document on this

NB : If I have thought about visualforce email but it seems that you can only add 1 related Object and I need 2

Regards

Best Answer chosen by Admin (Salesforce Developers) 
kirkevonphillykirkevonphilly

{!Proposal__c.Company__r.Description__c}

{!Proposal__c.Product__r.Description__c}

 

That is how you would typically traverse the relationship from the Proposal object one of related record's fields.  I don't believe the merge field will work in an email template  unless the Loopup field is a master-detail.

 

A common workaround is to create a hidden formula field on the parent object and reference that in your email template.  The formula field for you would just be {!Company__r.Description}, for example.  

 

If you were to explore the Visualforce template idea, I don't see why you couldn't create a new Visualforce Component and embed that in your VF template.  You could pass into the Visualforce Component your Recipient and Related object IDs.  Then the Component itself would be able to make use of its own custom controller to do any additional heavy lifting.

 

 

All Answers

kirkevonphillykirkevonphilly

{!Proposal__c.Company__r.Description__c}

{!Proposal__c.Product__r.Description__c}

 

That is how you would typically traverse the relationship from the Proposal object one of related record's fields.  I don't believe the merge field will work in an email template  unless the Loopup field is a master-detail.

 

A common workaround is to create a hidden formula field on the parent object and reference that in your email template.  The formula field for you would just be {!Company__r.Description}, for example.  

 

If you were to explore the Visualforce template idea, I don't see why you couldn't create a new Visualforce Component and embed that in your VF template.  You could pass into the Visualforce Component your Recipient and Related object IDs.  Then the Component itself would be able to make use of its own custom controller to do any additional heavy lifting.

 

 

This was selected as the best answer
Karthikeyan MBKarthikeyan MB
Tried multiple combinations like above, but dint work. Then found the below note:
You can’t use a lookup field as a merge field in an email template. You can, however, create a hidden formula field on the page layout that pulls the value from the lookup field. Then include the hidden field in the email template.
Ref: https://help.salesforce.com/apex/HTViewHelpDoc?id=valid-merge-fields.htm&language=en

Thanks