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
Prady01Prady01 

Merge fields on the email template for approval comments

Hi there, I have an approval process and in this approval process I have added an email template with merge fields (ApprovalRequest.Comments) for comments and this template I have used in the final rejection action as an email alert but when I receive the email, I get this field value as blank even though the user has entered the comment, I did also search and found that

 

ApprovalsIf the email template you choose contains approval merge fields named{!ApprovalRequest.field_name}, these fields will return values only when that email template is used as the approval assignment template. If you use the template for any other email alert action—in either workflow rules or approval processes—the merge fields will return a null value.

 

Any help/comments on this is greatly appreciated

 

Thanks

Pradeep

Best Answer chosen by Admin (Salesforce Developers) 
Prady01Prady01

Hi all, Hopefully this might help someone, As per salesforce support, We won be able to capture the approval/rejection comments in the email text template using the merge fileds.

 

 Since this was need for me to get done, I did it using the Visualforce Email template.

 

Thanks

Pradeep

All Answers

DevADSDevADS

Hello Pradeep,

 

The {!ApprovalRequest.Comments} merge field can be used in any approvals-related email alert from Salesforce Winter'14 Release.

Previously, all approval merge fields named {!ApprovalRequest.field_name} returned values only when used in an
approval assignment email template. When used in templates for other email alert actions—in workflow rules or approval
processes—the approval merge fields returned null.


Example : if a request is rejected at any approval step, you can include the approver’s rejection comment in an email
alert to the submitter.


Note: The {!ApprovalRequest.Comments} merge field returns only the most recently entered comment in
emails for an approval step that requires unanimous approval from multiple approvers.

 

Thanks,

Amit Shingavi

Prady01Prady01

Hi all, Hopefully this might help someone, As per salesforce support, We won be able to capture the approval/rejection comments in the email text template using the merge fileds.

 

 Since this was need for me to get done, I did it using the Visualforce Email template.

 

Thanks

Pradeep

This was selected as the best answer
jarrodmichaeljarrodmichael

Hi Pradeep,

Can you share how you got the Approval Comments within the Visualforce template?

Prady01Prady01

Hi there, Sure why not, I had to make a component, Apex controller and an visualforce email template.

 

1. Apex class

public with sharing class AccountApprovalReject {
    public String accIds {get;set;}
    public Account acc{get;set;}
    Public ProcessInstanceStep pStep{get;set;}
    Public String sfdcBaseURL{get;set;}
    
 public AccountApprovalReject (){
     
 }
 public ProcessInstanceStep getApprovalSteps() {
      if (accIds != null) {
        pStep = [Select SystemModstamp, StepStatus, ProcessInstanceId, OriginalActorId,OriginalActor.Name,
        Comments, ActorId From ProcessInstanceStep where ProcessInstance.TargetObjectId=:accIds order by SystemModstamp desc Limit 1];  
        
      }
      return pStep ;
    }
    
 Public Account getAccounts(){
     if (accIds != null) {
         acc = [Select id,name,Owner.Name from Account where id=:accIds Limit 1];
        
     }
     
     return acc;
 }
 
 Public String getURL(){
      if (accIds != null) {
          sfdcBaseURL = URL.getSalesforceBaseUrl().toExternalForm()+'/'+acc .id;
      }
      return sfdcBaseURL;
 }
 
}

 Component:

<apex:component controller="AccountApprovalReject" access="global">
    <apex:attribute name="accId" assignTo="{!accIds}" type="String" description="Id of the cont"/> 
    
    <br/>
    <b>Account Name</b>:             {!Accounts.Name} <br/>
    <b>Submitter</b>:           {!Accounts.Owner.Name} <br/>
    <b>Rejection Comments</b>:  {!ApprovalSteps.Comments} <br/>
    <b>Account Link</b>:        <apex:outputLink value="{!URL}" title="Contact">Click to view account</apex:outputLink>
             
</apex:component>
                           

 Template

<messaging:emailTemplate subject="Your Account is Rejected" recipientType="User" relatedToType="Account">
<messaging:HtmlEmailBody >
The following submitted Account request as been rejected. 
Below are the approval rejection comments
<html>
<head>
    <meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
    <meta name="Template" content="Response"/>
</head>
<body>

<c:AccountApprovalReject accId="{!relatedTo.Id}"/>

</body>
</html>
</messaging:HtmlEmailBody>
</messaging:emailTemplate>

 Hope it helps!

Prady

jarrodmichaeljarrodmichael
Thank you Prady!

Thanks,
*____________________________________________________________
Jarrod Kingston *