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
Daniel MasonDaniel Mason 

Different VF email templates trigged by picklist value ?

HI All

I am slowly loosing the will to live at the moment, and I don’t know whether I am over complication the situation or not.

Currently I have an object called “Certificates” Which sits on the contact and is only used by one profile “Retail”

There are currently two record types ;
CPD Certificate
Certificate of Attendance

Dependent on the record type you choose, you are generated with an email template.

Now I don’t want to create a separate record type for a new profile to use the object.  I want to use the existing record type, but identify which profile within the record type, and generate the email from there.

To do this I have created a picklist field called “team” and I have the following two values ;

If the user selects “Retail” I want the existing email template to be sent out

<messaging:emailTemplate subject="{!relatedTo.Date__c} {!relatedTo.RecordType.Name} {!relatedTo.Name}" recipientType="Contact" relatedToType="Certificate__c">
    <messaging:htmlEmailBody >
        <p>Dear {!recipient.FirstName},</p>
        <p>Please find attached your {!relatedTo.RecordType.Name} for the event you attended on&nbsp;<c:DisplayFormattedDate date_time_value="{!relatedTo.Date__c}" date_time_format="EEE MMM d kk:mm:ss z yyyy"/>.</p>
        <p>Kind Regards,</p>
        <hr />        
        <c:Attendance_Certificate Certificate="{!relatedTo}" />
    <messaging:plainTextEmailBody >
        Dear {!recipient.FirstName},
        Please find attached your {!relatedTo.RecordType.Name} for the event you attended on {!day(relatedTo.Date__c)}/{!month(relatedTo.Date__c)}/{!year(relatedTo.Date__c)}
        Kind Regards,
    <messaging:attachment renderAs="PDF" filename="{!relatedTo.RecordType.Name}_{!relatedTo.Name}.pdf">
                <c:Attendance_Certificate Certificate="{!relatedTo}"/>

however if they select “Institutional” a new email template is generated.

also how can i amend the details within the PDF ? as for the new Institutional email template, there is a different MD, And registration number etc

Looking forward to your help 



Can this be done ?


Hi ,

See the snippet below, 


Try the below code snippet as reference:

------------- vf page--------------
<apex:page controller="redirectonthebasisonpicklist" >
<Apex:form >
     <apex:selectList value="{!picklistvalue}" size="1" >
     <Apex:selectOptions value="{!item}"/>
    <apex:actionSupport event="onchange" action="{!redirect}" />   


--------------- apex controller --------------

public class redirectonthebasisonpicklist
public list<selectoption>item{get;set;}
public string picklistvalue{get;set;}
public redirectonthebasisonpicklist()
    item=new list<selectoption>();
    item.add(new selectoption('addtocontact','add to contact'));
    item.add(new selectoption('AddtoAssociate','Add to Associate'));

public pagereference redirect()
     PageReference pageRef= new PageReference('/apex/'+picklistvalue);
    return pageRef;



Daniel MasonDaniel Mason

HI Ashish

I am very New to Apex & VF, what does the following do ? 

Hi Daniel, 

The above added code is split in 2 parts which will help you get the functionality of selecting the picklist value and redirecting to the specific visualforce page. 

The 1st part has to be configured in the Visualforce page in which you want that functionality. 

The 2nd part has to be added in a controller extension which will be called by the Visualforce page. 

See the below links,