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

VF Email Template

Hi All


I am trying to create a visual force Email template. I wanted to add custom object fields in the email template. I created a apex controller, component and i called the component in to VF page template but still unable to find out the custom fields in the VF template which i added in the component. Here is the thing i did




public class CAFApprovalHistoryController {
   public CAF__c cf;
    public String cafId {get;set;}
    public List<ProcessInstanceHistory> getApprovalSteps() {
      if (cafId != null) {
        CAF__c cafs = [Select Id, Name, CAPEX_Total__c, Off_Net_Circuit_Expense_Total__c, CAF_IRR__c, of_Revisions__c, Sales_Rep__c, Sales_Manager__c, Account__c, CAF_Title1_del__c, CAF_1__c, Products_Requested__c, Bandwidth__c, Notes_of_Consideration__c, CAF_Link__c, (Select TargetObjectId, SystemModstamp, StepStatus, RemindersSent, ProcessInstanceId, OriginalActorId, IsPending, IsDeleted, Id, CreatedDate, CreatedById, Comments, ActorId From ProcessSteps order by SystemModstamp desc) from CAF__c where Id = :cafId];
        return cafs.ProcessSteps;
      return new List<ProcessInstanceHistory> ();
  public CAF__c getcaf(){
  return cf;


Component. Blue are the custom object fields which i added in the component. But, i am unable to see those in the VF email template


<apex:component controller="CAFApprovalHistoryController" access="global">
    <apex:attribute name="cafId" assignTo="{!cafId}" type="String" description="Id of the CAF"/> 
    <apex:dataTable value="{!approvalSteps}" var="step">
        <apex:column value="{!step.SystemModstamp}" headerValue="Date"/>
        <apex:column value="{!step.StepStatus}" headerValue="Status"/>
        <apex:column value="{!step.OriginalActorId}" headerValue="Assigned To"/>
        <apex:column value="{!step.ActorID}" headerValue="Actual Approver"/>
        <apex:column value="{!step.Comments}" headerValue="Comments"/>
        <apex:outputLabel value="CAF" for="CAF__c.CAFId">
        <apex:pageBlockSection >
        <apex:outputField id="CAPEX" value="{!CAF.CAPEX_Total__c}"/>
        <apex:outputField id="OffNetCircuitExpense" value="{!CAF.Off_Net_Circuit_Expense_Total__c}"/>
        <apex:outputField id="SalesManager" value="{!CAF.Sales_Manager__c}"/>


And i called the above component in the VF template mentioned in Red in the below code. Here is my VF Template.


<messaging:emailTemplate subject="Your CAF has been Rejected" recipientType="User" relatedToType="CAF__c">
<messaging:HtmlEmailBody >
Your CAF has been rejected.
Below are the approval rejection comments
    <meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
    <meta name="Template" content="Response"/>
<b>Capital Planning will follow up on the rejection of this CAF.  Please do not reply to this e-mail.</b>
<b>CAF Details</b>
<p><b>Approval History</b>
<c:CAF_Approval_History_Component cafId="{!relatedTo.Id}"/>







Afzal MohammadAfzal Mohammad

You may want to check the field level security for those fields.


Hope that helps.