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
b.gonzalezb.gonzalez 

VisualForce Email Template:Error: Unknown property

I created the following VF email template. However I am recieving the following Error: Unknown property 'core.email.template.EmailTemplateComponentController.Opportunity'

 

See VF email template below:

<messaging:emailTemplate subject="Channel Special Pricing Approval Request:{!relatedTo.name}" recipientType="User" relatedToType="Opportunity">
<messaging:plainTextEmailBody >
<html>
<body>
<p>
A new Channel Special Pricing Request has been submitted for your review and is pending your approval.  The link provided will take you to the opportunity in Salesforce.com.  If you are receiving this on your mobile devise, a summary of the opportunity details follows below the link.
</p>
<p>
You can approve or deny this request from your mobile devise by replying to this message and typing approved or rejected in the first line of the email body.  You may add any additional comments in the second and subsequent lines.  The additional comments will be added to your approval or denial record.
</p>
 <STYLE type="text/css">
               TH {font-size: 11px; font-face: arial;background: #CCCCCC; border-width: 1;  text-align: center } 
               TD  {font-size: 11px; font-face: verdana } 
               TABLE {border: solid #CCCCCC; border-width: 1}
               TR {border: solid #CCCCCC; border-width: 1}
         </STYLE>
        <font face="arial" size="2">  
 <table border="0" >
                 <tr > 
                     <th>Action</th><th>Product Name</th><th>Quantity</th><th>Disti Price</th><th>Discount%</th><th>Discount $</th><th>Discount Price</th>
                  </tr>
    <apex:repeat var="opp" value="{!relatedTo.OpportunityLineItems}">
       <tr>
           <td><a href="https://na1-blitz01.soma.salesforce.com/{!opp.id}">View</a> |  
           <a href="https://na1-blitz01.soma.salesforce.com/{!opp.id}/e">Edit</a></td>
           <td>{!opp.PriceBookEntry.name}</td>
           <td>{!ROUND(opp.Quantity,0)}</td>
           <td>{!ROUND(opp.ListPrice,0)}</td>
           <td>{!ROUND(opp.Discount__c,0)}</td>
           <td>{!ROUND(opp.Discount,0)}</td>
           <td>{!ROUND(opp.Requested_Price__c,0)}</td>
       </tr>
    </apex:repeat>                 
       </table>
       <p />
 </font>
<h4>Opportunity Detials:</h4>
<table border="1">
<tr>
<th>Opportunity Name: {!Opportunity.Name}</th>
<th>Channel Request Authorization: {!Opportunity.ChannelRequestAuthorization__c}</th>
</tr>
<tr>
  <td>QLogic Sales Person (Opportunity Owner):</td>
  <td>{!Opportunity.OwnerFullName}</td>
</tr>
<tr>
  <td>Distributor:</td>
  <td>{!Opportunity.Distributor__c}</td>
</tr>
<tr>
  <td>Reseller:</td>
  <td>{!Opportunity.Reseller__c}</td>
</tr>
<tr>
  <td>End User:</td>
  <td>{!Opportunity.Account}</td>
</tr>
<tr>
  <td>End User Website:</td>
  <td>{!Account.Website}</td>
</tr>
<tr>
  <td>Competitor:</td>
  <td>{!Opportunity.Competitor1__c}</td>
</tr>
<tr>
  <td>Partner Status:</td>
  <td>{!Opportunity.Partner_Status__c}</td>
</tr>
<tr>
  <td>Opportunity Comments:</td>
  <td>{!Opportunity.OpportunityComments__c}</td>
</tr>
<tr>
  <td>Opportunity Amount:</td>
  <td>{!Opportunity.Amount}</td>
</tr>
<tr>
  <td>Approved Opportunity Value:</td>
  <td>{!Opportunity.Approved_Opportunity_Value__c}</td>
</tr>
<tr>
  <td>POS Value Claimed:</td>
  <td>{!Opportunity.POS_Value_Claimed__c}</td>
</tr>
<tr>
  <td>Net Opportunity POS:</td>
  <td>{!Opportunity.Net_Opportunity_POS__c}</td>
</tr>
<tr>
  <td>Total Credit Claimed:</td>
  <td>{!Opportunity.Total_Credit_Claimed__c}</td>
</tr>
<tr>
  <td>Max Discount %:</td>
  <td>{!Opportunity.Max_Discount__c}</td>
</tr>
</table>
</body>
</html>
</messaging:plainTextEmailBody>
</messaging:emailTemplate>
Best Answer chosen by Admin (Salesforce Developers) 
Puja_mfsiPuja_mfsi

Hi,

Because the three fields Distributor,reseller and end User are Lookup fields. They contains ID values .you need to access the name with relationship like:

 

<td>Distributor:</td>
<td>{!relatedTo.Distributor__r.name}</td>    <!--__r for relationship -->

 

<td>Reseller:</td>
<td>{!relatedTo.Reseller__r.name}</td>

 

<td>End User:</td>
<td>{!relatedTo.Account.Name}</td>

 

 

Please let me know if u have any problem on same and if this post helps u please throw KUDOS by click on star at left.

 

 

 

 

All Answers

Puja_mfsiPuja_mfsi

HI,

In Vf template you put "relatedToType="Opportunity" " , So if you want to access the fields of opportunity u need to access as :

{!relatedTo.name}  Not  {!opportunity.name} 

 

So u need to replace {!opportunity.name}  to {!relatedTo.name}   etc.. for all fields.

 

 

Please let me know if u have any problem on same and if this post helps u please through KUDOS by click on star at left.

b.gonzalezb.gonzalez

Hi Puja,

 

Thank you! That seemed resolve my error.  I used the "send test and verify merge fields" button to verify the fields are merging properly.  In the test email, I returned what appeard is the ID number for the Reseller, Distributor, and End User field and not the acutal data in these fields. Not sure what this is happening. 

 

I attached my update VF page code:

<messaging:emailTemplate recipientType="User"
    relatedToType="Opportunity"
    subject="Channel Special Pricing Approval Request: {!relatedTo.name}">
    
<messaging:htmlEmailBody >        
    <html>
        <body>
         <STYLE type="text/css">
               TH {font-size: 13px; font-face: arial;background: #CCCCCC; border-width: 1;  text-align: center } 
               TD  {font-size: 13px; font-face: verdana } 
               TABLE {border: solid #CCCCCC; border-width: 1}
               TR {border: solid #CCCCCC; border-width: 1}
         </STYLE></p></body>
                  <font face="arial" size="2">
        <p>Dear Approver,</p><p>A new Channel Special Pricing Request has been submitted for your review and is pending your approval.The link provided will take you to the opportunity in Salesforce.com. If you are receiving this on your mobile devise, a summary of the opportunity details follows below the link.</b></p>
        <p>You can approve or deny this request from your mobile devise by replying to this message and typing approved or rejected in the first line of the email body.</p>
        </body>
        <table border="0" >
                 <tr > 
                     <th>Action</th><th> Product Name </th><th> Quantity </th><th> Disti Price $ </th><th> Discount %</th><th> Discount Price $ </th>
                  </tr>
    <apex:repeat var="opp" value="{!relatedTo.OpportunityLineItems}">
       <tr>
           <td><a href="https://na1-blitz01.soma.salesforce.com/{!opp.id}">View</a> |  
           <a href="https://na1-blitz01.soma.salesforce.com/{!opp.id}/e">Edit</a></td>
           <td>{!opp.PriceBookEntry.name}</td>
           <td>{!ROUND(opp.Quantity,0)}</td>
           <td>{!ROUND(opp.ListPrice,0)}</td>
           <td>{!ROUND(opp.Discount__c,0)}</td>
           <td>{!ROUND(opp.Requested_Price__c,0)}</td>
           </tr>
     
    </apex:repeat>                 
       </table>
       <br/>
       <table border="1" >
       <tr>
<th>Opportunity Name: {!relatedTo.Name}</th>
<th>Channel Request Authorization: {!relatedTo.ChannelRequestAuthorization__c}</th>
</tr>
<tr>
  <td>QLogic Sales Person (Opportunity Owner):</td>
  <td>{!relatedTo.Name}</td>
</tr>
<tr>
  <td>Distributor:</td>
  <td>{!relatedTo.Distributor__r}</td>
</tr>
<tr>
  <td>Reseller:</td>
  <td>{!relatedTo.Reseller__c}</td>
</tr>
<tr>
  <td>End User:</td>
  <td>{!relatedTo.Account}</td>
</tr>
tr>
  <td>Competitor:</td>
  <td>{!relatedTo.Competitor1__c}</td>
</tr>
<tr>
  <td>Partner Status:</td>
  <td>{!relatedTo.Partner_Status__c}</td>
</tr>
<tr>
  <td>Opportunity Comments:</td>
  <td>{!relatedTo.OpportunityComments__c}</td>
</tr>
<tr>
  <td>Opportunity Amount:</td>
  <td>{!relatedTo.Amount}</td>
</tr>
<tr>
  <td>Approved Opportunity Value:</td>
  <td>{!relatedTo.Approved_Opportunity_Value__c}</td>
</tr>
<tr>
  <td>POS Value Claimed:</td>
  <td>{!relatedTo.POS_Value_Claimed__c}</td>
</tr>
<tr>
  <td>Net Opportunity POS:</td>
  <td>{!relatedTo.Net_Opportunity_POS__c}</td>
</tr>
<tr>
  <td>Total Credit Claimed:</td>
  <td>{!relatedTo.Total_Credit_Claimed__c}</td>
</tr>
<tr>
  <td>Max Discount %:</td>
  <td>{!relatedTo.Max_Discount__c}</td></tr>
       <p />
 </font>
        </body>
    </html>
</messaging:htmlEmailBody> 
    
<messaging:plainTextEmailBody >
Dear Approver,
 
A new Channel Special Pricing Request has been submitted for your review and is pending your approval.The link provided will take you to the opportunity in Salesforce.com. If you are receiving this on your mobile devise, a summary of the opportunity details follows below the link.

You can approve or deny this request from your mobile devise by replying to this message and typing approved or rejected in the first line of the email body.


[ Product Name ] - [ Quantity ] - [ Unit Price ] - [ Total Price ]
-------------------------------------------------------------------------

<apex:repeat var="opp" value="{!relatedTo.OpportunityLineItems}">
[ {!opp.PriceBookEntry.name} ] - [ {!ROUND(opp.Quantity,0)} ] - [ {!ROUND(opp.UnitPrice,0)} ] - [ {!ROUND(opp.TotalPrice,0)} ]
</apex:repeat>

</messaging:plainTextEmailBody>       
        
</messaging:emailTemplate>

 

 

Puja_mfsiPuja_mfsi

Hi,

Because the three fields Distributor,reseller and end User are Lookup fields. They contains ID values .you need to access the name with relationship like:

 

<td>Distributor:</td>
<td>{!relatedTo.Distributor__r.name}</td>    <!--__r for relationship -->

 

<td>Reseller:</td>
<td>{!relatedTo.Reseller__r.name}</td>

 

<td>End User:</td>
<td>{!relatedTo.Account.Name}</td>

 

 

Please let me know if u have any problem on same and if this post helps u please throw KUDOS by click on star at left.

 

 

 

 

This was selected as the best answer
Anant KamatAnant Kamat
For Standard Objects append .Name against the Id fields. For Custom Objects just append <Custom Object__r>.Name to get the name values and not Ids.
Hemalatha DacherlaHemalatha Dacherla
Hi,

I have created a Visualforce Template and unable to execute. I have 3 objects involved in this. 
Account
Asset and 
ProAct Alarm(custom obj)
Please let me know how I can include the rest 2 objects in the relatedtotype, so I can add field mapping of those objects too.

Here is my code:
<messaging:emailTemplate recipientType="Contact"
  relatedToType="Account"
  subject="ProAct Alarm Report: {!relatedTo.name}"
  replyTo="test.test@emerson.com">
  <messaging:htmlEmailBody >
    <html>
      <body>
        <STYLE type="text/css">
          td
{border-left:1px solid black;
border-top:1px solid black; font-size: 11px; font-face: arial;}
table
{border-right:1px solid black;
border-bottom:1px solid black;}
.firstTr {
    border:1px solid black;
}
        </STYLE>
        <font face="arial" size="2">
          <p>Dear {!recipient.name},</p>
          <table width="70%">
            <tr><th colspan="10"  style="background-color: gray;">Site Information</th></tr>        
        <tr>
            <td colspan="2"><strong>Customer</strong></td>
            <td colspan="3">{!relatedTo.Parent}</td>
            <td colspan="2"><strong>Store Phone</strong></td>
            <td colspan="3">{!relatedTo.Phone}        
        </td>
        </tr>
        <tr>
                <td colspan="2"><strong>Site</strong></td>
                <td  colspan="3">{!relatedTo.Name}</td>
                <td colspan="2"><strong>Ctrl. Manufacturer</strong></td>
                <td colspan="3">CPC</td>
            </tr>
            <tr>
                    <td colspan="2"><strong>Site Alias</strong>
                        </td>
                    <td colspan="3">N/A</td>
                    <td colspan="2"><strong>City</strong>
                        </td>
                    <td colspan="3">{!relatedTo.BillingCity}
                </td>
                </tr>
                <tr>
                        <td colspan="2"><strong>State-Zip-Country</strong>  
                            </td>
                        <td colspan="3">{!relatedTo.BillingState}    
                            </td>
                        <td colspan="2"><strong>Address</strong>
                            </td>
                        <td colspan="3">           
                    </td>
                    </tr>
                    <tr><th colspan="10" style="background-color: gray;">Alarms</th></tr>
                    <tr>                       
                        <td>Alarm ID</td>
                        <td>Time Occurred</td>
                        <td>Time Received</td>
                        <td>Raw Source</td>
                        <td>Raw Desc</td>
                        <td>Property Name</td>
                        <td>Property Value</td>
                        <td>Controller Type</td>
                        <td>Controller Name</td>
                        <td>RTN</td>
                    </tr>

                    <tr>                       
                            <td>314442230</td>
                            <td>11/20/2018  6:23:00 AM</td>
                            <td>11/20/2018  11:35:36 AM</td>
                            <td>COMP A2 ALARM</td>
                           <td>COMMAND OUT</td>
                            <td>ON</td>
                            <td>E2</td>
                            <td>UNIT A</td>
                            <td>FALSE</td>
                        </tr>
    </table><br></br>
    <p>Regards.<br></br>
        </font>
      </body>
    </html>
  </messaging:htmlEmailBody> 
 
</messaging:emailTemplate>