Visualforce Email Template with custom controller

Visualforce Email Template with custom controller

Apex Controller:

public  class acctTemplt
    public Id accountId {get;set;}
    public List<Opportunity> getopptys()
        List<Opportunity> oppty;
        oppty = [SELECT Name, StageName FROM Opportunity WHERE Accountid =: accountId];
        return oppty;

Visualforce Component:


<apex:component controller="acctTemplt" access="global">
    <apex:attribute name="AcctId" type="Id" description="Id of the account" assignTo="{!accountId}"/>
    <table border = "2" cellspacing = "5">
            <td>Opportunity Name</td>
            <td>Opportunity Stage</td>               
        <apex:repeat value="{!opptys}" var="o">

Visualforce Email template:

<messaging:emailTemplate subject="List of opportunity" recipientType="User" relatedToType="Account">
    <messaging:htmlEmailBody >
    Below is the list of opportunities for your account {!relatedTo.Name}.<br/><br/>
    <c:OpptyList AcctId="{!relatedTo.Id}" /><br/><br/>


Leave a Reply