1
사용자 지정 클래스를 사용하는 구성 요소를 만들었습니다. 이 구성 요소를 전자 메일 서식 파일에 추가했습니다. 템플릿을로드하려고하면이 오류 메시지가 나타납니다. 목록에 SObject에 할당 할 행이 없습니다. 내가 만든 속성이 내 수업에 가치를 전달하지 않는다고 말할 수 있습니다.SalesForce의 전자 메일 템플릿에서 ID가 사용자 지정 컨트롤러에 전달되지 않습니다.
또한 이메일을 보내려면 작업 페이지를 먼저 가져 오면 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>
에이 클래스
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;
}
}