Print this page

How to include approval comments in an visualforce email template?

Knowledge Article Number 000004192
Description

Include approval comments in an visualforce email template.

Resolution

Sample code on how to include approval comments in Visualforce email template:

===============VF template==============================

<messaging:emailTemplate subject="test" recipientType="Contact" relatedToType="Account">

<messaging:plainTextEmailBody >

<c:approvalcomments2 ObjectId="xyz" StepStatusMes="Approved" rendered="true"></c:approvalcomments2> // the id can be changed based on your requirement this is just a sample

</messaging:plainTextEmailBody>

</messaging:emailTemplate>

 

Component:

<apex:component controller="FindQuoteApprovalComments" access="global">

<apex:attribute   assignTo="{!objId}" name="ObjectId" description="Object Id"/>

<apex:attribute assignTo="{!StepStatusMessage}" type="String" description="Object Id"/>

<apex:dataTable value="{!quoteApprovalComments}" var="s_ApprovalComments">

<apex:column>

<apex:facet name ="heater"> Approval comments </apex:facet>

{!s_ApprovalComments.comments}

</apex:column>

</apex:dataTable>

</apex:component>

====

Controller

public with sharing class FindQuoteApprovalComments {

 public ApprovalComments;

 public string objId { get; set; }

 public string StepStatusMessage { get; set; }

public List<ProcessInstanceStep> ProcessInstanceSteps;

 

 public findQuoteApprovalComments() {

    ApprovalComments = 'Approval email Comments';

    ProcessInstanceSteps= new List<ProcessInstanceStep>([Select p.Comments, p.ProcessInstance.TargetObjectId from ProcessInstanceStep p  WHERE p.ProcessInstance.TargetObjectID = :objId AND StepStatus =:StepStatusMessage]);

}

 

public List<ProcessInstanceStep> getQuoteApprovalComments()

 { return ProcessInstanceSteps; }

}

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_email_templates_intro.htm





promote demote