• snh_nit
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies

Hi,

 

I'm building a Visualforce Email Template consisting of a component, custom controller and a Visualforce email template. See here for details: http://boards.developerforce.com/t5/Visualforce-Development/Visualforce-email-template-issue/m-p/440361/highlight/true#M50419

 

Now, I have everything working except for one little thing - and that is the recepientType.

 

For some reason, I cannot seem to access that field/value without getting an error back.

 

I've tried accessing the field like this: {!recipient.name} but then I'm told that there is no such variable in my controller (which is correct).

 

My assumption was then, that because I have a custom controller to go with the component, I would need to fetch the contact (recipientType) in the controller. However, when I passing recipientType to my controller my template stops working (I get the "list has no rows" error which I assume is a related issue but not the real one).

 

I've tried passing recipientType to my controller as {!recipient}, {!recipientType} and {!recipientType.Id}. None of which seem to be working for me.

 

Any clues?

 

/Søren Nødskov Hansen

Hi all,

 

I have a Visualforce email template which includes a component which has it's own custom controller. I use this setup in order to be able to retrieve related objects which I want to display in the email going out to a contact.

 

However, for some reason, nothing gets displayed in my email templates and I haven't found a way of debugging it in order to be able to track when/where it goes wrong. However, I'm fairly certain that it is the opportunity ID that does not get passed from the template/component to the controller.

 

I've searched for an answer but haven't been able to find one. I've seen similar posts (e.g.. http://forums.sforce.com/t5/Apex-Code-Development/Custom-Controller-in-Email-Template-not-passing-values-to-Class/m-p/134744) but for some reason I still haven't been able to make it work in my own org.

 

Here is my component:

 

<apex:component id="cmpOrderForm" controller="OrderFormDomainOppComponentController" access="global">
	<apex:attribute name="paramOppId" description="Passes the ID of the opportunity to the custom controller" type="Id" assignTo="{!oppId}"/>
	<apex:outputText value="{!oppId}"/>
	<html>
		<body>
			<table>
				<apex:repeat value="{!links}" var="lnk">
					<tr>
						<td>Domain Name</td>
						<td>{!lnk.Domain__r.Name}</td>
					</tr>
				</apex:repeat>
			</table>
		</body>
	</html>
</apex:component>

 Here is my template:

<messaging:emailTemplate recipientType="Contact" relatedToType="Opportunity" subject="Order Form" replyTo="soren.nodskov@capgemini.com">
    <messaging:htmlEmailBody >
    	<c:OrderFormDomainOppComponent paramOppId="{!relatedTo.Id}"/>
    </messaging:htmlEmailBody>
</messaging:emailTemplate>

 Here is my controller:

public without sharing class OrderFormDomainOppComponentController {
	private final List<DomainOppLink__c> links;

	public Id oppId {get; set;}

	public OrderFormDomainOppComponentController() {
		// oppId = '006W0000002VDzZ';
		links = [SELECT Domain__r.Name FROM DomainOppLink__c WHERE Opportunity__c = :oppId];
	}

	public List<DomainOppLink__c> getLinks() {
		return links;
	}
}

 In the template I output the Opportunity ID just for debugging purposes and that works fine. It shows the ID correctly when testing the template from within the SF GUI (Setup --> Communication Templates --> Email Templates).

 

However, the DomainOppLink objects retrieved in the controller is not shown. If I hard code the opportunity ID in my controller (commented out in the code above), it all works fine. I.e.. I get an email with all the DomainOppLink objects.

 

So, the big WHY is: WHY doesn't it work when I am NOT hard coding the opportunity ID but using the ID passed on from my component/template?!

 

I feel like I'm SO close, and that I just cannot seen the forrest for all the trees.

 

All help is greatly appreciated.

 

Cheers.

 

/Søren Nødskov Hansen

Hi all,

 

I have a Visualforce email template which includes a component which has it's own custom controller. I use this setup in order to be able to retrieve related objects which I want to display in the email going out to a contact.

 

However, for some reason, nothing gets displayed in my email templates and I haven't found a way of debugging it in order to be able to track when/where it goes wrong. However, I'm fairly certain that it is the opportunity ID that does not get passed from the template/component to the controller.

 

I've searched for an answer but haven't been able to find one. I've seen similar posts (e.g.. http://forums.sforce.com/t5/Apex-Code-Development/Custom-Controller-in-Email-Template-not-passing-values-to-Class/m-p/134744) but for some reason I still haven't been able to make it work in my own org.

 

Here is my component:

 

<apex:component id="cmpOrderForm" controller="OrderFormDomainOppComponentController" access="global">
	<apex:attribute name="paramOppId" description="Passes the ID of the opportunity to the custom controller" type="Id" assignTo="{!oppId}"/>
	<apex:outputText value="{!oppId}"/>
	<html>
		<body>
			<table>
				<apex:repeat value="{!links}" var="lnk">
					<tr>
						<td>Domain Name</td>
						<td>{!lnk.Domain__r.Name}</td>
					</tr>
				</apex:repeat>
			</table>
		</body>
	</html>
</apex:component>

 Here is my template:

<messaging:emailTemplate recipientType="Contact" relatedToType="Opportunity" subject="Order Form" replyTo="soren.nodskov@capgemini.com">
    <messaging:htmlEmailBody >
    	<c:OrderFormDomainOppComponent paramOppId="{!relatedTo.Id}"/>
    </messaging:htmlEmailBody>
</messaging:emailTemplate>

 Here is my controller:

public without sharing class OrderFormDomainOppComponentController {
	private final List<DomainOppLink__c> links;

	public Id oppId {get; set;}

	public OrderFormDomainOppComponentController() {
		// oppId = '006W0000002VDzZ';
		links = [SELECT Domain__r.Name FROM DomainOppLink__c WHERE Opportunity__c = :oppId];
	}

	public List<DomainOppLink__c> getLinks() {
		return links;
	}
}

 In the template I output the Opportunity ID just for debugging purposes and that works fine. It shows the ID correctly when testing the template from within the SF GUI (Setup --> Communication Templates --> Email Templates).

 

However, the DomainOppLink objects retrieved in the controller is not shown. If I hard code the opportunity ID in my controller (commented out in the code above), it all works fine. I.e.. I get an email with all the DomainOppLink objects.

 

So, the big WHY is: WHY doesn't it work when I am NOT hard coding the opportunity ID but using the ID passed on from my component/template?!

 

I feel like I'm SO close, and that I just cannot seen the forrest for all the trees.

 

All help is greatly appreciated.

 

Cheers.

 

/Søren Nødskov Hansen