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
Bob_zBob_z 

Visualforce Notes and Attachments Body field Name?

I am trying to create a visualforce email template, and I cannot get the "Body " field to work without getting an error.

 

What is the field name for that field using what I have below for code?

 

 

<apex:repeat value="{!RelatedTo.NotesAndAttachments}" var="NotesAndAttachments">
<tr><td>
Note: {!NotesAndAttachments.Note.Body}</td></tr>
</apex:repeat>

 

Best Answer chosen by Admin (Salesforce Developers) 
mtbclimbermtbclimber

Thanks. I wasn't thinking about email templates. Does this not work for you?

 

 

<messaging:emailTemplate subject="Opportunity With Notes" recipientType="User" relatedToType="Opportunity">
    <messaging:plainTextEmailBody >
        <apex:outputText value="{!relatedTo.name}"/>
        <apex:repeat value="{!relatedto.notes}" var="note">
            <apex:outputText value="{!note.title}"/>
            <apex:outputText value="{!note.body}"/>
        </apex:repeat>
    </messaging:plainTextEmailBody>
</messaging:emailTemplate>

 

 

All Answers

mtbclimbermtbclimber

There is no "Note" relationship on NoteAndAttachment.  Try using the "Notes" child relationship instead of "NotesAndAttachments".

Bob_zBob_z

That didn't work. 

mtbclimbermtbclimber

Should have looked more closely. Where is "RelatedTo" coming from?  You may be trying to do something that isn't possible in one traversal today.

Bob_zBob_z

I'm trying to pull the information from opportunities. I did get the owner, email and created date fields to work. I can't help but think I'm not naming it correctly. 

mtbclimbermtbclimber

Ok, and those refer to the opportunity as "RelatedTo"? It would help to see the parts of your page that are working and the relevant parts of your controller and/or extension(s).

Bob_zBob_z

<messaging:emailTemplate subject="Cybex Opportunity" recipientType="User" relatedToType="Opportunity">
<messaging:HtmlEmailBody >

 

 

<body>
<b>CYBEX Opportunity</b><br />

 

<table  cellpadding="5" cellspacing="0" border="0" width="100%">
<apex:repeat value="{!RelatedTo.Name}" >

  <tr>

      <td align="left"><i><b>Account Name:</b></i>
       {!Relatedto.Account.Name}</td></tr>

   <tr>
        <td align="left"><i><b>Opportunity Name:</b></i>
        {!Relatedto.Name}</td></tr>

 

   <b>Opportunity Contact</b><br/>

   <table  cellpadding="5" cellspacing="0" border="0" width="100%">

           
<apex:repeat value="{!RelatedTo.OpportunityContactRoles}" var="ContactRole">

    <tr>
        <td align="left"><i><b>Name:</b></i>
        {!ContactRole.Contact.Name}</td></tr>
     
     <tr>
        <td align="left"><i><b>Phone:</b></i>
        {!ContactRole.Contact.Phone}</td></tr>
      
     <tr>
        <td align="left"><i><b>Mobile Phone:</b></i>
         {!ContactRole.Contact.MobilePhone}</td></tr>
     
     <tr>
        <td align="left"><i><b>Email:</b></i>
        {!ContactRole.Contact.Email}</td></tr>
     
     <tr>
        <td align="left"><i><b>Street:</b></i>
        {!ContactRole.Contact.Shipping_Street_1__c}</td></tr>
     
     <tr>
        <td align="left"><i><b>City:</b></i>
         {!ContactRole.Contact.Shipping_City__c}</td></tr>
     
     <tr>
        <td align="left"><i><b>Zip Code:</b></i>
     
       {!ContactRole.Contact.Shipping_Zip_Postal_Code__c}</td></tr>
      
     <tr>
        <td align="left"><i><b>Country Code:</b></i>
        {!ContactRole.Contact.Shipping_Country_Code__c}</td></tr>

 

     </apex:repeat></table>

 

<apex:repeat value="{!RelatedTo.ActivityHistories}" var="ActivityHistory">
   <tr><td><b>Date:</b> {!ActivityHistory.ActivityDate}</td></tr>
   <tr><td><b>Subject:</b> {!ActivityHistory.Subject}</td></tr>
   <tr><td><b>Status:</b> ({!ActivityHistory.Status})</td> </tr>
   <tr><td  valign="top"><b>Comments:</b><br /> {!ActivityHistory.Description}</td> </tr>
   
</apex:repeat></table>

 

</body>
</html>
</messaging:htmlEmailBody>
</messaging:emailTemplate>

mtbclimbermtbclimber

Thanks. I wasn't thinking about email templates. Does this not work for you?

 

 

<messaging:emailTemplate subject="Opportunity With Notes" recipientType="User" relatedToType="Opportunity">
    <messaging:plainTextEmailBody >
        <apex:outputText value="{!relatedTo.name}"/>
        <apex:repeat value="{!relatedto.notes}" var="note">
            <apex:outputText value="{!note.title}"/>
            <apex:outputText value="{!note.body}"/>
        </apex:repeat>
    </messaging:plainTextEmailBody>
</messaging:emailTemplate>

 

 

This was selected as the best answer
Bob_zBob_z

Of coarse it works, as usually I always think it can't be that simple. Thanks for your help!

LalitLalit

Is it possible to add all the attachment from notestandattachment section with Visual-force email template.


In the company with sales-form user update Attachment(contains Rebate check detail or item description).
In Approval e-mail request Accounting/Finance team needs to see all the attached document under Notes&Atachment section.