I am trying to build an email template that lists all the OpportunityLineItems in the email body. Can I use the <apex: relatedList> tag? That is what I am trying to do with the code below, but I am not having any success. Can anyone tell me if this is possible, and if so, what my issue is? Thanks in advance.

<messaging:emailTemplate subject="Opportunity {!relatedTo.Opportunity_Number__c} has been booked and requires Software Fulfillment" recipientType="User" relatedToType="Opportunity">
<messaging:plainTextEmailBody >
FICO Software Fulfillment Team,
Opportunity {!relatedTo.Opportunity_Number__c} has been booked and requires Software Fulfillment.


<apex:relatedList list="OpportunityLineItems"/>


1 Answer 1


You cannot use relatedList component inside messaging. It would not really format well anyways since you are using plaintext body. Try using a repeat tag like:

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

You probably want to change the formatting a bit so it looks better.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .