+ Start a Discussion
sundhar.mks1.3962649227519546E12sundhar.mks1.3962649227519546E12 

How to get the Opportunity product information to email template?

Hi,

I have added the number of product to Opportunity. how to call the product information email template?

Is this need to add the product to price book entry before add the template? Kindly give any example

Thanks
KaranrajKaranraj
Visualforce email template can do it for you. Here is the sample visualforce email template
<messaging:emailTemplate subject="Opportunity product" recipientType="Contact" relatedToType="Opportunity">
<messaging:plainTextEmailBody >
Congratulations!
This is your new Visualforce Email Template.
Opportunity Name : {!relatedTo.Name}
Below are the Opportunity line items
<apex:repeat value="{!relatedTo.OpportunityLineItems}" var="line">
{!line.Name}
</apex:repeat>
</messaging:plainTextEmailBody>
</messaging:emailTemplate>

 
sundhar.mks1.3962649227519546E12sundhar.mks1.3962649227519546E12
Hi

I have tried below code but i got error: Missing required attribute relatedToType="" when using {!relatedTo}.How to solve this?

<apex:repeat value="{!relatedTo.OpportunityLineItems}" var="line">
    <tr>
      <td>{!Line.Product Code}"/></td>
      <td>{!Line.Quantity}"/></td>
      <td>{!Line.Product Description}"/></td>
      <td>{!Line.Sales Price}"/></td>
    </tr>
    </apex:repeat>

If we need add the product to OpportunityLineItems before call the template?
KaranrajKaranraj
You want to get the products information associate with the opportunity in your email template right? If it is yes then goto Setup->emailTemplate->New Template->Visualforce Fill all the required information and in the related to section select Opportunity and then paste the above code.

This template will display the Opportunity and its OpportunitylineItems(prodcuts associate with the opportunity record)

 
sundhar.mks1.3962649227519546E12sundhar.mks1.3962649227519546E12
Hi Karanraj,

I have used the code to email template there is i got a error.Kindly refer the bwlow code

Email template
===================
<messaging:emailTemplate subject="Product Information" recipientType="User" >
<messaging:plainTextEmailBody >
Dear Customer,
This is your new Visualforce Email Template.
</messaging:plainTextEmailBody>
  <messaging:attachment renderAs="pdf">
<head>
<style>
@page {
  size: auto;   /* auto is the initial value */
  margin-top: 0.0%;
  margin-left: 4mm;
  margin-right: 4mm;
  margin-bottom: 4mm;
}
td{
font-family:Arial,Helvetica,sans-serif;
font-weight:normal;
font-size:15px;
}
.tds{
font-family:Arial,Helvetica,sans-serif;
font-weight:normal;
font-size:15px;
}
td.normal{
font-family:Arial,Helvetica,sans-serif;
font-weight:normal;
font-size:15px;
}
td.nbold{
font-family:Arial,Helvetica,sans-serif;
font-weight:bold;
font-size:15px;
}
</style>
</head>
    <tr>
       <td  width = "14%"><b>Product Code</b></td>
       <td  width = "10%"><b>Quantity</b></td>
       <td  width = "44%"><b>Product Description</b></td>
       <td  width = "44%"><b>Sales Price</b></td>
       
    </tr> 
    <apex:repeat value="{!relatedTo.OpportunityLineItems}" var="line">
    <tr>
      <td>{!Line.Product Code}"/></td>
      <td>{!Line.Quantity}"/></td>
      <td>{!Line.Product Description}"/></td>
      <td>{!Line.Sales Price}"/></td>
   
    </tr>
    </apex:repeat>
    
    <tr><td>&nbsp;</td></tr>        
    <tr><td>&nbsp;</td></tr>
     
        
</messaging:attachment> 

</messaging:emailTemplate>
KaranrajKaranraj
There is no relatedtotype in the first line of the code. just replace the first line with the below code
<messaging:emailTemplate subject="Product Information" recipientType="User" relatedToType="Opportunity">
sundhar.mks1.3962649227519546E12sundhar.mks1.3962649227519546E12
Hi,

When i add the this line <apex:repeat value="{!relatedTo.OpportunityLineItems}" var="line"> i got following Eror. how to solve this?

Error: Missing required attribute relatedToType="" when using {!relatedTo}.
sundhar.mks1.3962649227519546E12sundhar.mks1.3962649227519546E12
Hi Karanraj,
               Changed the first line but product Information does not pullthrough to emil template,