2009-07-01 102 views
1

我創建了一個使用自定義類的組件。我將這個組件添加到電子郵件模板。當我嘗試加載模板時,這是我收到的錯誤消息。 列表中沒有行分配給SObject。從我可以告訴我創建的屬性沒有將價值傳遞給我的課程。ID未從SalesForce的電子郵件模板傳遞到自定義控制器

此外,當我第一次拉起任務頁面發送電子郵件時,OpportunityID是查詢字符串的一部分,其密鑰爲p3_lkid。但是,當我選擇模板時,querystring被重置。

我附上了下面的相關代碼。

組件

<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類

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; 
    } 


} 

回答

1

我認爲它可能必須處理你在構造函數中訪問opportunityID變量的事實。在設置任何變量之前,首先調用構造函數。你可能想把這個邏輯放在setter中。