0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

商談商品のレコードをメールテンプレートに表示する

Last updated at Posted at 2022-05-17

元の質問 : Email with Multiple OrderItems

初めにこれを見つけて回答していたのですが、実際に設定してみると保存できん。

Adding Opportunity Products Related List to Visualforce Email Template

relatedTo.OpportunityLineItems がない。そうだよねぇ。

<apex:repeat value="{!relatedTo.OpportunityLineItems}" var="oli">
   <apex:outputText value="{!oli.PriceboonEntry.Product2.Name}">
   <apex:outputText value="{!oli.UnitPrice}">
   <apex:outputText value="{!oli.Quantity}">
</apex:repeat>

過去に作ったものを参考に作ってみました。

PDFを作成し、Salesforceメールテンプレートに添付する方法

VF page email template

<messaging:emailTemplate subject="{!relatedTo.Name}" recipientType="User" relatedToType="Opportunity">
<messaging:plainTextEmailBody >

<c:ReceiptOppItems opportunityId="{!relatedTo.Id}"/>


</messaging:plainTextEmailBody>
</messaging:emailTemplate>

ReceiptOppItems.vfc

<apex:component controller="ReceiptOppItemsController" access="global">
    
    <apex:attribute name="opportunityId" description="Opportunity Id" assignTo="{!OpportunityObjectId}" type="Id" />   
    
    <apex:repeat value="{!OpportunityLineItems}" var="oli">
        <apex:outputText value="{!oli.PricebookEntry.Product2.Name}"/>
        <apex:outputText value="{!oli.UnitPrice}"/>
        <apex:outputText value="{!oli.Quantity}"/>
    </apex:repeat>
</apex:component>

ReceiptOppItemsController.apex

global class ReceiptOppItemsController {
    
    global String OpportunityObjectId{ 
        get;
        set {
            UpdateContents2(value);
        } 
    }
    
  
    
    global List<OpportunityLineItem> OpportunityLineItems{ get; set; }    
   
    public void UpdateContents2(String OpportunityObjectId) {
        
        if (OpportunityObjectId != null) {
            OpportunityLineItems = [SELECT Id,UnitPrice,Quantity,PricebookEntry.Product2.Name FROM OpportunityLineItem WHERE OpportunityId =:OpportunityObjectId];
           
            
        }
    }

}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?