+ Start a Discussion
Simon WhightSimon Whight 

Assistance formatting a Custom Controller for a Visualforce Email

I have a button on an contract record. When pressed, it will fire off a Visualforce Email to some internal email addresses. The email setup has a relatedtoType of Account which allows me to pull in the information I need from the related objects.

Where I am struggling is that the technique of Apex Repeat cannot guarantee it will pull in the latest Contract when run. So I need a custom controller to pull back the correct Contract information for my email - essentially the record where the button was pressed.

So far, I have the controller with all my vital data for my email:
 

public class findContract {
   
public String conID {get; set;}

    private final List<Contract> contracts;

    public findContract() {
        contracts= [SELECT Id, StartDate, Business_Type__c, Affinity__c, ContractTerm,  CompanySigned.name, CompanySignedDate, CustomerSigned.name, CustomerSignedDate, CustomerSignedTitle, 
        EndDate, Services_Taken_AI_Only__c, Services_Taken_AI_Only_HS__c, Services_Taken_Advice_Only__c, Services_Taken_Advice_Only_HS__c, Services_Taken_Franchise_Comp_EL__c, 
        Services_Taken_Franchise_Comp_HS__c, Services_Taken_Consultancy__c, Services_Taken_Franchise_Entry_EL__c, Services_Taken_Env__c, 
        Services_Taken_eRAMS__c, Services_Taken_FRA__c, Services_Taken_HS__c, Services_Taken_SBP__c, Services_Taken_Training__c, Services_Taken_JIT__c, H_S_Notes__c, 
        Finance_Notes__c, PEL_Notes__c, SpecialTerms FROM Contract WHERE Id = :conID LIMIT 1];   
          }

    public List<Contract> getContract() {
        return contracts;
    }
}
Now I need assistance with the Component and referencing it in the email.

Obviously, I need the Component to pick off the record ID where the my send email button is hosted to populate conID for the SOQL, so there is that element.

Also, the results of the query are displayed in a sequence of stacked fixed width tables like this:
 
<!--Table 9 **************************************************************************************-->
         
         <table border="1" width="1200px" >
           <col width="600"/>
           <col width="600"/>
           <tr>
            <th>BDM</th>
            <th>Date Signed</th>
          </tr>
          <tr>
           <td width="600"/>
           <td width="600"/>
          </tr>  
          <tr>
            <apex:repeat var="ctrtx" value="{!relatedTo.Contracts}" rows="1">          
            <td align="center">{!ctrtx.CompanySigned.Name}</td>
            <td align="center">  <apex:outputText value="{0,date,dd/MM/yyyy}">
                  <apex:param value="{!ctrtx.CompanySignedDate}" /> 
                  </apex:outputText>  </td>
            </apex:repeat> 
          </tr>
        </table>

So I need a way of breaking up the information and mimicking that style. So a big list of tables in the Component.

Can anyone help?