Vandevelde Jan

Certified Salesforce Consultant || Salesforce MVP

For Developers

Create an approval notification with Visualforce Email Template containing Quote and QuoteLineItems

Have you ever had the following business requirement?

You all know that when you submit a record for approval you can have an email notification sent to the approver with some mergefields of the record to be approved and a link that takes the approver immediately to the approvalpage.

But what if that email should also contain childrecords, like for example when you have to submit a quote for approval containing the QuoteLineItems in the approval request email, so that the approver can immediately decide without having to go into Salesforce to review what you are offering your customer.

Brian had some trouble with that and asked for help on the Salesforce Community and I wanted to challenge myself and give him a hand with it. 

Brian Gardner (Dialight)

Hi All. I am stuck and hoping for some help. I need to create a Quote Approval Process Email Template that can show the ALL individual Quote Line Items with additional fields. Each of our Quote Line Items can have different discounts and I need to be able to provide the information in an email template. This way our approvers can respond via email.

I am well aware of the Idea that is out there to be voted on, so please don’t send me that link. It also is apparent that this is not going to be doable with the Out of the Box Email Template builder, and I believe it is not possible using Visual Force email Template.

I am assuming that I am not the only one with this issue out there. So I am looking for some feedback and ideas on how you have solved this issue.


The difficulty in the approval notification is actually not the VisualForce template itself (see my post The not so scary Visualforce email template), but getting the approval URL in there ????

I first thought I’d go to the approval page, get the url, pass it the record id and use the well known URL-hack, but nooo it was more complex than that!

I have to say I needed to Google this and the classes beneath are from a fellow blogger called Liron. Thanks Liron for your clear explanation!

The id in that URL is not of the user, nor of the object being approved but it’s the ProcessInstanceWorkitem ID that is appended. So for that we need some apex classes which we will be able to use for any object in the future!

So this is how we go about it:

NOTE: all classes and components can be reused on every object in your future Visualforce email templates.

Step 1: Create an apex class called cls_createApprovalURL (this will generate the URL) .

public class cls_createApprovalURL{  
    public static String generateApprovalURL(String recordID){  
      String url='';  
      List workItemLst =   
        [  SELECT id  
      FROM ProcessInstanceWorkitem  
      WHERE processInstance.TargetObjectId=:recordID];   
      if(workItemLst.size() > 0)  
        url='https://'+ System.URL.getSalesforceBaseUrl().getHost() +   
         '/p/process/ProcessInstanceWorkitemWizardStageManager?id=' + workItemLst[0].id;      
     return url;  

Step 2: Create an apex class called cls_CmpApprovalURL (we will pass the id to the createApprovalURL class to generate the URL)

public class cls_CmpApprovalURL{  
   public String recID {get; set;}  
    public String urlStr{  
     return cls_createApprovalURL.generateApprovalURL(recID);  

Step 3: Create an Visualforce component called CmpApprovalURL (we will use this component in our actual Visualforce email template to generate the Link for the approver to go immediately to the approval page)


 Step 4: Create the Email Template containing the component


# Aman 2018-04-25 14:50

I used the same solution but VF component controller is not called.

Can you please let me know the reason.
Reply | Reply with quote | Quote

Add comment

Security code

On Twitter

Contact Info

Jan Vandevelde

Ninoofsesteenweg 42

9450 Denderhoutem


Mobile: +32 (0) 472 58 47 67


Email Address:

VAT BE 0882 025 057