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 

VF email template - related list on opportunity object?

Creating a VF email tempate for the opportunity object. On the opportunity object we have a related list called Note to Distributor (API Name: Note_to_Distributor__c). I am trying to have the Note to Distributor to appear in the the VF emial template. 

I am recieving the following error: Invalid field Note_to_Distributor__c for SObject Opportunity. This is the section of the code regarding the error. I am not sure why API Name for Note to Distributor is incorrect?
<apex:repeat var="noteToDis" value="{!relatedTo.Note_to_Distributor__c}">
              <tr>
                <td><a href="https://cs16.salesforce.com/{!noteToDis.id}">View</a> |  
                <a href="https://cs16.salesforce.com/{!noteToDis.id}/e">Edit</a></td>
                <td>{!noteToDis.Note_To_Distributor_Body__c}</td>
                <td>{!noteToDis.CreatedDate)}</td>
              </tr>
         </apex:repeat>

Here is the entire VF Email Template Code:
<messaging:emailTemplate recipientType="Contact"
  relatedToType="Opportunity"
  subject="New Note to Distributor: {!relatedTo.ChannelRequestAuthorization__c}"
  replyTo="pmiprogrammanager@qlogic.com">
  <messaging:htmlEmailBody >
    <html>
      <body>
        <STYLE type="text/css">
          H3 {color: #004488}
          TH {font-size: 13px; font-face: arial; color: #004488; background: #dfdfdf;
               border-width: 1;  text-align: center } 
          TD  {font-size: 11px; font-face: arial } 
          TABLE {border: solid #CCCCCC; border-width: 1}
          TR {border: solid #CCCCCC; border-width: 1}
        </STYLE>
        <font face="arial" size="2">
      <h3>Request:{!relatedTo.ChannelRequestAuthorization__c}- New Note</h3>    
          <p>A new note has been added to the opportunity request. Please see details below. For more information regarding this registration,login into your PMI account and or contact your Qlogic Channel Sales Representative.</p>
          <table border="1" >
            <tr> 
               <th>Request Details</th>
            </tr>
            <tr>    
               <td><b>Channel Authorization Number:</b></td>
           <td>{!relatedTo.ChannelRequestAuthorization__c}</td>
            </tr>
            <tr>    
               <td><b>Distributor:</b></td>
           <td>{!relatedTo.Distributor__r.Name}</td>
           </tr>    
           <tr>
               <td><b>Reseller:</b></td>
           <td>{!relatedTo.Reseller__r.Name}</td>
            </tr>
            <tr>
               <td><b>End User:</b></td>
           <td>{!relatedTo.Account.Name}</td>
            </tr>
            <tr>
              <th>Product List</th><th>Quantity </th>
            </tr>
            <apex:repeat var="opp" value="{!relatedTo.OpportunityLineItems}">
              <tr>
                <td><a href="https://cs16.salesforce.com/{!opp.id}">View</a> |  
                <a href="https://cs16.salesforce.com/{!opp.id}/e">Edit</a></td>
                <td>{!opp.PriceBookEntry.name}</td>
                <td>{!ROUND(opp.Quantity,0)}</td>
              </tr>
         </apex:repeat>  
            <apex:repeat var="noteToDis" value="{!relatedTo.Note_to_Distributor__c}">
              <tr>
                <td><a href="https://cs16.salesforce.com/{!noteToDis.id}">View</a> |  
                <a href="https://cs16.salesforce.com/{!noteToDis.id}/e">Edit</a></td>
                <td>{!noteToDis.Note_To_Distributor_Body__c}</td>
                <td>{!noteToDis.CreatedDate)}</td>
              </tr>
          </apex:repeat>                
       </table>
      <p/>
   </font>
  </body>
 </html>
</messaging:htmlEmailBody>  
</messaging:emailTemplate>

I appreciate the help!

Beth
 
Best Answer chosen by b.gonzalez
Neetu_BansalNeetu_Bansal
Hi Beth,

As per this screenshot, you need to use Notes_to_Distributor__r. So the code will look like:
<apex:repeat var="noteToDis" value="{!relatedTo.Notes_to_Distributor__r}">
              <tr>
                <td><a href="https://cs16.salesforce.com/{!noteToDis.id}">View</a> |  
                <a href="https://cs16.salesforce.com/{!noteToDis.id}/e">Edit</a></td>
                <td>{!noteToDis.Note_To_Distributor_Body__c}</td>
                <td>{!noteToDis.CreatedDate)}</td>
              </tr>
         </apex:repeat>

Thanks,
Neetu
 

All Answers

Neetu_BansalNeetu_Bansal
Hi Beth,

As opportunity object have related list called Note to Distributor (API Name: Note_to_Distributor__c). You need to use the child relationship name here. I guess it would be Note_to_Distributors__r. So your code would be like this:
<apex:repeat var="noteToDis" value="{!relatedTo.Note_to_Distributors__r}">
              <tr>
                <td><a href="https://cs16.salesforce.com/{!noteToDis.id}">View</a> |  
                <a href="https://cs16.salesforce.com/{!noteToDis.id}/e">Edit</a></td>
                <td>{!noteToDis.Note_To_Distributor_Body__c}</td>
                <td>{!noteToDis.CreatedDate)}</td>
              </tr>
         </apex:repeat>
Please try this, and let me know if it resolve your problem.

Thanks,
Neetu
b.gonzalezb.gonzalez
Hi Neetu,

Thank you. But I am still recieving the same error. 

Beth
Neetu_BansalNeetu_Bansal
Hi Beth,

This should work, are you sure that your child relationship name for Note_to_Distributor__c is Note_to_Distributors__r.

Please double check the relationship name and if still you are not able to resolve it, I need to look into your salesforce org.

Thanks,
Neetu
 
b.gonzalezb.gonzalez
The Note to Distributor custom object was created by someone else. They don't have a Master-Detial Relationship field on the this object but they do have Lookup Relationship field: Opportunity__c. The Child Relationship Name is Notes_to_Distributor. See image below. 

User-added image
Neetu_BansalNeetu_Bansal
Hi Beth,

As per this screenshot, you need to use Notes_to_Distributor__r. So the code will look like:
<apex:repeat var="noteToDis" value="{!relatedTo.Notes_to_Distributor__r}">
              <tr>
                <td><a href="https://cs16.salesforce.com/{!noteToDis.id}">View</a> |  
                <a href="https://cs16.salesforce.com/{!noteToDis.id}/e">Edit</a></td>
                <td>{!noteToDis.Note_To_Distributor_Body__c}</td>
                <td>{!noteToDis.CreatedDate)}</td>
              </tr>
         </apex:repeat>

Thanks,
Neetu
 
This was selected as the best answer
b.gonzalezb.gonzalez
That did the trick. I was missing 's' in Notes. 

Thank you for the help!

Beth
EGA FuturaEGA Futura
https://medium.com/@cynthiabellmcgillis/todays-the-day-write-your-first-visualforce-email-template-fbbdeec2592c