+ Start a Discussion
Kim WojnoKim Wojno 

Error with Visualforce Email Template

Hello!
I am trying to create a new template but everytime i try to reference the opportunity I get this.
Error: Unknown property 'core.email.template.EmailTemplateComponentController.Opportunity

Here is the code:
<messaging:emailTemplate subject="WeddingWire Receipt" recipientType="Contact" relatedToType="Opportunity">
<messaging:htmlEmailBody >

<p style="font-family: Helvetica, Arial, sans-serif; font-size: 12px">Hi {!recipient.name},</p>
<p style="font-family: Helvetica, Arial, sans-serif; font-size: 12px">Congratulations! You now have access to premium WeddingWire benefits. Your order has been processed successfully. Here are the details:
</p>
<p style="font-family: Helvetica, Arial, sans-serif; font-size: 12px">
<strong>Confirmation Number: </strong><apex:outputField value="{!Opportunity.Transaction_ID__c}"/>
<br></br>
<strong>Product:</strong>
<br></br>
<br></br>
<strong>Total Contract Value: </strong>
<br></br>
<br></br>
<strong>Sales Price: </strong>{!Opportunity.Amount}
<br></br>
<strong>Payment Plan: </strong>
<br></br>
<strong>Installment Amount:  </strong>
<br></br>
<strong>Sales Rep: </strong>
<br></br>
<strong>Term: </strong>12 Months
<br></br>
<br></br>

'
Best Answer chosen by Kim Wojno
Suneel#8Suneel#8
You should try as below.relatedTo it self serves as Opportunity because of declaration relatedToType="Opportunity".Can you try below way

{!relatedTo.Transaction_ID__c}

All Answers

Suneel#8Suneel#8
You should use relatedTo to reference Opportunity.You can check the sample template in the below link

http://www.salesforce.com/docs/developer/pages/Content/pages_compref_messaging_emailTemplate.htm
Kim WojnoKim Wojno
I did try that before posting this, but I get "Invalid field Opportunity for SObject Opportunity" as an error. The fied I am trying to reference is a custom field on the opportunity. 
Suneel#8Suneel#8
You might have encountered that error as you referred to field as {!relatedTo.Opportunity} in the template.And that error message is valid.Opportunity field is not part of Opportunity object. Can you share screenshot of the template with the error message.
Kim WojnoKim Wojno
I see what your saying, but how will it the recognize the merge field?
User-added image
Kim WojnoKim Wojno
Congratulations!Here are the details:<br></br>
            <strong><br></br>
            Confirmation Number: </strong>{!relatedTo.Opportunity.Transaction_ID__c}<br></br>
            <strong>Product:</strong>  <br></br> <br></br>
            <strong>Product:</strong> <br></br></br><br>
            <br>
            <strong>Total Contract Value: </strong>$ 5220.00<br><strong>
Suneel#8Suneel#8
You should try as below.relatedTo it self serves as Opportunity because of declaration relatedToType="Opportunity".Can you try below way

{!relatedTo.Transaction_ID__c}
This was selected as the best answer
Kim WojnoKim Wojno
peftec, that worked!