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
sgottreusgottreu 

Custom Controller in Email Template not passing values to Class

I have created a component that is using a custom class.  I added this component to an email template.  When I try and load the template this is the error message I receive. List has no rows for assignment to SObject. From what I can tell the attribute I have created is not passing the value to my class.

 

Also, when I first pull up the task page to send an email, the OpportunityID is part of the querystring with a key of p3_lkid. However, when I select the template the querystring is reset.  I have enclosed the relevant code below.

 

 

Component

 <apex:component access="global" controller="ProbeQuoteEmail">
<apex:attribute name="opportunityID"
description="This is the ID of the opportunity."
type="ID" assignTo="{!opportunityID}" />

<apex:repeat value="{!ProbeProducts}" var="p">
<p>{!p.ProductFamily__c}</p>
<table border='1'>
<apex:repeat value="{!p.OpportunityLineItems}" var="line">

<tr>
<td ><apex:outputText value="{!line.Quantity}"/></td>
<td ><apex:outputText value="{!line.PricebookEntry.Name}"/></td>
<td align="right"><apex:outputField value="{!line.UnitPrice}"/></td>
<td align="right"><apex:outputField value="{!line.TotalPrice}"/></td>
</tr>

</apex:repeat>
</table>
</apex:repeat>

</apex:component>


Email Template


<messaging:emailTemplate subject="Your requested quote n° {!relatedTo.Id}" recipientType="Contact" relatedToType="Opportunity">
<messaging:plainTextEmailBody >
Dear {!recipient.name},

Thank you for your continued interest in our offering. Please see the attached quote per your request.

Feel free to contact me if you have any questions.

Regards,
{!$User.FirstName} {!$User.LastName}

</messaging:plainTextEmailBody>
<messaging:attachment renderAs="pdf" filename="{!relatedTo.name}">

<c:ProbeQuoteProducts opportunityID="{!relatedTo.Id}"/>

</messaging:attachment>


</messaging:emailTemplate>

Apex Class


public class ProbeQuoteEmail {
Schema.DescribeFieldResult F = Product2.Family.getDescribe();
List<Schema.PicklistEntry> P = F.getPicklistValues();

public Opportunity Probe { get; set; }

public Id opportunityID { get; set; }

public List<Opportunity> ProbeProducts = new List<Opportunity>();

Integer Counter = 1;

public ProbeQuoteEmail() {

for (Schema.PicklistEntry fam:P){
Integer i = 0;
String FamilyLabel = fam.GetLabel();

Probe = [SELECT o.Id, o.Name, o.Amount, o.ProductFamily__c, (SELECT op.Quantity, op.UnitPrice, op.TotalPrice,
op.PricebookEntry.Name, op.OpportunityId, op.PricebookEntry.ProductCode,
op.PricebookEntry.Product2.Family, op.LineCount__c
FROM OpportunityLineItems op WHERE op.PricebookEntry.Product2.Family = :FamilyLabel)
FROM Opportunity o where Id = :opportunityID];

Probe.Amount = 0;
Probe.ProductFamily__c = FamilyLabel;

for(i=0;i<Probe.opportunityLineItems.size();i++) {
Probe.Amount += Probe.opportunityLineItems[i].TotalPrice;
Probe.opportunityLineItems[i].LineCount__c = Counter;
Counter++;
}

ProbeProducts.add(Probe);
}
}

public List<Opportunity> getProbeProducts() {
return ProbeProducts;
}


}
Message Edited by sgottreu on 07-01-2009 01:26 PM
Message Edited by sgottreu on 07-01-2009 02:15 PM
Best Answer chosen by Admin (Salesforce Developers) 
sf42_Tobisf42_Tobi

Hi Scott,

 

I ran into the same issue today, debug stopped after calling the page with the mailform.

Searching the community I discovered your post and compared the Code.

 

There is just one little problem. There is no Id in the component.

 

You have to pass the Id inside your class, that's because there is no PageId used. You wrote that it's in the p3_lkid but the class doesn't know this:

 

 

if (opportunityId == NULL) {
opportunityId = ApexPages.CurrentPage().getParameters().get('p3_lkid');
}

 

In the component I also changed assignTo into opportunity.Id and now it works fine in my org.


<apex:component access="global" controller="ProbeQuoteEmail">
<apex:attribute name="opportunityID" description="This is the ID of the opportunity." type="ID" assignTo="{!opportunity.ID}" />
<apex:repeat value="{!ProbeProducts}" var="p">
(...)
</apex:repeat>
</apex:component>


with these changes, I get my mailform and the attached pdf with the repeat over the lineitems.

 

I hope this also works for you.

 

Good luck,

Tobias Forstmeier

Message Edited by sf42_Tobi on 07.08.2009 11:30 AM
Message Edited by sf42_Tobi on 07.08.2009 11:31 AM

All Answers

wesnoltewesnolte

Hey

 

From what I can see you may be setting the value to the correct value and then to null. The assignTo attribute set's the public property, you don't have to perform the

 

 opportunityID = ApexPages.CurrentPage().getParameters().get('id');

 

It should be set by this point. Remove this line and let me know how it goes. You may want to include some System.debug messages in your apex code too, this will makes things quite a bit simpler. You can then view these messages from the in-browser debug logs.

 

Cheers,

Wes 

sgottreusgottreu
I took out the code you suggested and still nothing.  I think it is because when I select the template, the URL gets reset and doesn't pass any of the querystring back to the page.  Any suggestions on how to fix it?
wesnoltewesnolte

Hmm.. a difficult one to troubleshoot. Have you tried system.debug() messages to narrow down the cause? Sorry it's a n00b suggestion but it's fundamental.

 

Cheers,

Wes

sgottreusgottreu
I have added in system.debug but the debug window does not appear on the page where I am sending the email.  Is there an option to turn on the debug window on every single page?
sf42_Tobisf42_Tobi

Hi Scott,

 

I ran into the same issue today, debug stopped after calling the page with the mailform.

Searching the community I discovered your post and compared the Code.

 

There is just one little problem. There is no Id in the component.

 

You have to pass the Id inside your class, that's because there is no PageId used. You wrote that it's in the p3_lkid but the class doesn't know this:

 

 

if (opportunityId == NULL) {
opportunityId = ApexPages.CurrentPage().getParameters().get('p3_lkid');
}

 

In the component I also changed assignTo into opportunity.Id and now it works fine in my org.


<apex:component access="global" controller="ProbeQuoteEmail">
<apex:attribute name="opportunityID" description="This is the ID of the opportunity." type="ID" assignTo="{!opportunity.ID}" />
<apex:repeat value="{!ProbeProducts}" var="p">
(...)
</apex:repeat>
</apex:component>


with these changes, I get my mailform and the attached pdf with the repeat over the lineitems.

 

I hope this also works for you.

 

Good luck,

Tobias Forstmeier

Message Edited by sf42_Tobi on 07.08.2009 11:30 AM
Message Edited by sf42_Tobi on 07.08.2009 11:31 AM
This was selected as the best answer