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 ;
Retail
Institutional

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>
        <p>{!recipient.Owner.Name}</p>
        <hr />        
        <c:Attendance_Certificate Certificate="{!relatedTo}" />
    </messaging:htmlEmailBody>
    <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,
        {!recipient.Owner.Name}
    </messaging:plainTextEmailBody>
    <messaging:attachment renderAs="PDF" filename="{!relatedTo.RecordType.Name}_{!relatedTo.Name}.pdf">
        <html>
            <body>
                <c:Attendance_Certificate Certificate="{!relatedTo}"/>
            </body>
        </html>
    </messaging:attachment>
</messaging:emailTemplate>



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 

KR 

D


Can this be done ?

Ashish_SFDCAshish_SFDC

Hi ,


See the snippet below, 

Hi,

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:selectList>


</Apex:form>
</apex:page>

--------------- 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);
    pageRef.setredirect(true);
    return pageRef;
}
}


Regards,

Ashish

Daniel MasonDaniel Mason

HI Ashish

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

Ashish_SFDCAshish_SFDC
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, 

https://developer.salesforce.com/page/Building_Visualforce_Pages_Using_the_Standard_Controller

http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_extension.htm


Regards,
Ashish