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
Complete noviceComplete novice 

Help for writing a custom controller and component for a VF email please

I've just about got my head around amending pre-written VF email templates but now find I need to write a custom controller and component, which means I am seriously out of my depth.

This is what I am trying to achieve:

An email to be sent from an opportunity.  It is sent to the primary opportunity contact and details the opportunity product, plus some fields from the Account record.  I can do this bit.  However I have also been asked to include specific contacts from the Account related contacts list.  

I understand this needs a custom controller and component but I don't understand how to build these.

Can anyone help me please? You would be helping me out of a massive hole!

This is the code I have so far which retuns the opportunity propduct and the Account record fields:

messaging:emailTemplate subject="Renewal." recipientType="Contact" relatedToType="Opportunity"
 replyTo="xxx@xxx.org" >
 
<messaging:htmlEmailBody >        
    <html>
        <body>
        <apex:image id="Email_Header"
value="https://c.cs84.content.force.com/servlet/servlet.ImageServer?id=xxxxx&oid=xxxxx"
height="130" width="600"/>

         <STYLE type="text/css">
                  TH {font-size: 14px; font-face: arial;background: #FFFFFF; border-width: 0;  text-align: center }
               TD  {font-size: 14px; font-face: arial }
             
             </STYLE>
           <font face="arial" size="2">
           <br/>
           <br/>
      <p/>  Dear  
    <apex:repeat value="{!RelatedTo.OpportunityContactRoles}" var="ContactRole">
<apex:outputText value=" {!ContactRole.Contact.Name}" rendered="{!AND(ContactRole.isPrimary)}"></apex:outputtext>

</apex:repeat>,
            <br/>
            <br/>       
        {!RelatedTo.Account.Name}'s membership expires on <apex:outputText value=" {0, date,EEEE d MMMM yyyy}"> <apex:param value="{!relatedTo.Asset_Expires_When__c}"/> </apex:outputtext>.
                    <br/>
       
Our records show the information below about your company:
<br/>
            <br/>
             <td><b>•   </b> Company Size: {!relatedTo.Account.Number_of_Employees__c} employees</td>
             <br/>
             <td><b>•   </b> Turnover: {!relatedTo.Account.CurrencyIsoCode} {!relatedTo.Account.AnnualRevenue}</td>

<p/>  <apex:repeat var="opp" value="{!relatedTo.OpportunityLineItems}">  
       <tr>
       <td><b>•   </b> Membership type {!opp.PriceBookEntry.name}.</td> <br/>
        </tr>
      </apex:repeat>  
      <br/>​


Thanks in advance.