Skip to main content

Hello everyone, we want to send an email confirmation to our customers when they finalize their order. We want to include the details of the OrderItems they selected. 

How can i include the details of the Order (parent object) (order items - Child object) into an email?

4 respuestas
  1. 17 may 2022, 05:07

    Hi ,

     

    The content of the article alone did not work.

    I think it works by using the VF component.

     

    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/9000