我创建了一个使用自定义类的组件。我将此组件添加到电子邮件模板中。当我尝试加载模板时,这是我收到的错误消息。 列表没有用于分配给SObject的行。据我所知,我创建的属性并没有将值传递给我的类。
此外,当我第一次启动任务页面发送电子邮件时,OpportunityID是查询字符串的一部分,其键为 p3_lkid 。但是,当我选择模板时,重置了查询字符串。
我附上了以下相关代码。
组件
<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>
电子邮件模板
<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;
}
}
答案 0 :(得分:1)
我认为这可能与您在构造函数中访问opportunityID变量这一事实有关。在设置任何变量之前,首先调用构造函数。您可能希望将此逻辑放入setter中。