+ Start a Discussion

Passing Attribute value in Custom Components used in VF Email template

Hello everyone,

I give up after 3 days of struggling with this. Below is simplified of what I want to do.

My goal is sending an Email template that is running a custom component that uses its own controller.

I want the custom component controller to collect the data required for the template while the Email template controller is only responsible of getting the right contactId, all this is order to be able to reuse my component in multiple templates.

I can't get it to work. What am I missing? Is there a simpler way than what is below? Your help is really appreciated.


The Email template Controller:

global with sharing class SenConVFTemCont {
global ID conId = ApexPages.currentPage().getParameters().get('conid');
public Contact contact;
global SenConVFTemCont(){
public Contact getContact(){
return contact = [Select Id, Email from Contact where Id =: conId];
public VOID senConVFTem(){
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
Messaging.sendEmail(new Messaging.singleEmailMessage[] {email} );

The Email page lauching the Email through button with URL = '/apex/SenConVFTem?conid={!contact.id}'

<apex:page controller="SenConVFTemCont" action="{!senConVFTem}" sidebar="false" showheader="false" id="SenConVFTem">

The component controller


global with sharing class NameTableCont {
global ID conID;
global ID conIdCom;
global Contact contact;
global NameTableCont(){
//conId='a03F0000009RKZj'; //testing purpose of component out of VF template
global ID getConId(){return ConID;}
global VOID setConIdCom(ID data){conIdCom=data;}


global contact getContact(){
return contact = [Select Id, name from Contact where id =: conIdCom];
global VOID setContact(Contact data){contact=data;}

The component


<apex:component access="global" controller="NameTableCont" id="NameTable" >
<apex:attribute name="IdConAP" type="Contact" description="This is the Id of the contact" assignTo="{!contact}" access="global" />
<p>This is the Component table</p>
<p>End of Component table</p>

The VF template


<messaging:emailTemplate subject="Here is your business card" recipientType="Contact" relatedToType="Account" id="PositionBusinessCard">
<messaging:htmlEmailBody >
HTML Email Body Position Business Card<br/>
<c:NameTable IdConAP="{!RelatedTo.Id}" /><br/>  Question: what does {!RelatedTo.Id} really do?

What I want as a result is below, but what I get is an empty line1 when I get the thing to send an Email



From: noreply@salesforce.com [mailto:noreply@salesforce.com] On Behalf Of ADMIN
Sent: Thursday, November 07, 2013 10:31 AM
To: jmaison92@gmail.com
Subject: Here is your business card




HTML Email Body Position Business Card


This is the Component table


line1:Jacques Maison


End of Component table



Again: thanks for your help.


Hi Jerome, 

See if this solves the problem, 

messaging:emailTemplate recipientType="Contact"


<messaging:emailTemplate subject="Thank you for your Support!" recipientType="Contact" >