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
FastSnailFastSnail 

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.

Jerome

The Email template Controller:

global with sharing class SenConVFTemCont {
global ID conId = ApexPages.currentPage().getParameters().get('conid');
public Contact contact;
global SenConVFTemCont(){
getContact();
}
public Contact getContact(){
return contact = [Select Id, Email from Contact where Id =: conId];
}
public VOID senConVFTem(){
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setTemplateID('00XF0000001KrA8');
email.setTargetObjectId(contact.Id);
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">
</apex:page>

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
getContact();
}
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>
line1:{!contact.name}<br/>
<p>End of Component table</p>
</apex:component>

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?
</messaging:htmlEmailBody>
</messaging:emailTemplate>

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.

Jerome

Ashish_SFDCAshish_SFDC
Hi Jerome, 


See if this solves the problem, 

messaging:emailTemplate recipientType="Contact"

https://groups.google.com/forum/#!topic/salesforce-professionals/silJxiWht04

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

ContactId="{!recipient.Id}"

http://gokubi.com/archives/visual-force-email-templates-2


Regards,
Ashish