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
Simon WhightSimon Whight 

Help making a simple controller for a Visualforce email

Hi. Fingers crossed this is simple.

I've made an email, it uses Account as the RelatedToType as it needs to source information from Contacts and Contracts. I had been using a Repeater to pull information from Contracts with a row limit of 1. What has transpired is that I cannot control the order in which information returns from the Repeater. I need the latest record, it will return whatever it has decided to pull back.

The result is that I need a controller to pull Contract information. This, right here, is where I am asking you for help. I haven't got a clue. 

It's not overly complex I would assume, just the latest related Contract record to the Account, and then a bit of guidance on how I replace the references to the repeater with the controller.

Thanks!
Simon WhightSimon Whight
Example code from my environment, I have a whole heap of small tabled segments that have information from Contracts in them:
 
<!--Table 14 **************************************************************************************-->
         
         <table border="0" width="900px" >
           <col width="450"/>
           <col width="450"/>       
           <tr>
            <th>Advice Only EL&amp;HR</th>
            <th>Advice Only H&amp;S</th>
          </tr>
          <tr>
           <td width="450"/>
           <td width="450"/>
          </tr>  
          <tr>
            <apex:repeat var="ctrtx" value="{!relatedTo.Contracts}" rows="1">          
            <td>{!IF(ctrtx.Services_Taken_Advice_Only__c=TRUE,"Yes","No")}</td>            
            <td>{!IF(ctrtx.Services_Taken_Advice_Only_HS__c=TRUE,"Yes","No")}</td>
            </apex:repeat> 
          </tr>
        </table>

      
      
BalajiRanganathanBalajiRanganathan
you have to Create VF component and then use that component in your VF Email template

you can refer the sample here

https://www.salesforce.com/us/developer/docs/pages/Content/pages_email_templates_with_apex.htm
Simon WhightSimon Whight
My logic sees:

1) Apex to query desirable object
2) VFpage to display object results in table
3) Refer to VFpage to pull in data to email

Sound right?
BalajiRanganathanBalajiRanganathan
yes, VFpage is not a regular VF page. it should be VF Component