You need to sign in to do that
Don't have an account?

Email Template (Cross Object Functionality)
Hello everyone,
I am seeking some help and advice regarding email templates.
Our ORG currently is configured with Accounts >> Opportunities >> Opportunity Line Items (multiple "items" per opp is possible).
What I'm trying to accomplish is:
Pull Account Information, Pull Opportunity Information, BUT ALSO pull Opportunity Line Items for an email template.
Currently, if I send an email template from the opportunity object, it only pulls account and opportunity information.
Anyone have the same problem? I've tried using VF/APEX templates but I'm pretty new to that.
Please help.
Thanks
I am seeking some help and advice regarding email templates.
Our ORG currently is configured with Accounts >> Opportunities >> Opportunity Line Items (multiple "items" per opp is possible).
What I'm trying to accomplish is:
Pull Account Information, Pull Opportunity Information, BUT ALSO pull Opportunity Line Items for an email template.
Currently, if I send an email template from the opportunity object, it only pulls account and opportunity information.
Anyone have the same problem? I've tried using VF/APEX templates but I'm pretty new to that.
Please help.
Thanks
Here is a sample that I found that seems to do what you are looking for.
Create this controller code for your component:
your component would look like this:
All Answers
There is no other way than doing this as a Visualforce template.
This sample should help:
http://wiki.apexdevnet.com/index.php/VisualForceEmailTemplates_sample
Here is a real simple example.
I got a part of it to work (where I put the Opp as the primary object) and cascaded down to retrieve Account and Opportunity Line Item info. Now comes the problem. The OppLineItem name (which is the exact thing I'm trying to pull) is a lookup to the Product object. Our product object is renamed "Services" and to pull the name, I have to use {!Product2.Name}. I'm not sure how to address this object and insert the product name.
I've tried making a new template where the primary object is 'Product2' :
<messaging:emailTemplate subject="New Win Announcement!" recipientType="User" relatedToType="Product2">
<messaging:htmlEmailBody >
<apex:datatable value="{!relatedto}" var="p">
Solution: <apex:column value="{!p.Solution__c}" ></apex:column>
Solution Segment: <apex:column value="{!p.Solution_Segment__c}" ></apex:column>
Service: <apex:column value="{!p.Name}" ></apex:column>
This seems to work fine, but how can I get account/opportunity info in this template? Can I cascade upwards from product?
Thanks in advance
Here is a sample that I found that seems to do what you are looking for.
Create this controller code for your component:
your component would look like this:
Cheers
Thanks again for your help. One thing I've noticed on my alerts is that the total opp amount shown is rendered as $50.0 instead of $50.00. (shows $50.1 instead of $50.10, but it will display $50.25 if it is $50.25)
Since we only use whole numbers, is there anyway to get rid of the decimal point? or make it show 2 decimals places over? Fields and their setup look fine, it's just pulling the data in a strange way.
I fixed the amount option by creating a roll up summary field (which pulls two decimal points over, instead of one).
But now, I'm running into a bigger problem with our end users:
I have setup a workflow that triggers an email alert (described above). The workflow kicks off when a stage of an opportunity is set to "Closed Won" and a picklist to send alert equals "Yes".
As an administrator, I can select both options and save the opportunity record (and workflow, email triggers).
BUT when an end users tries to do the same, he's prompted with an error:
" Error: Invalid Data.
Review all error messages below to correct your data.
You do not have sufficient privileges to access the controller: SortedLineItemsController"
Do you know why this is happening?
Here is my controller:
Any help is appreciated. I'm under a deadline and can't seem to figure it out. Is it in the code or something I have to change under the salesforce setup?
Nice! Thanks.... I figured it out right when you were probably writing this :)
Cheers!
Hi guys,
thanks, this was pretty useful.
I just customized the controller quering the DB using SELECT and ORDER BY.
I'm now stuck with the TEST class.
Should I test only the controller or also the component ?
any help/suggestion is appreciated.
Thanks
Alex
I have a simialr, if different issue, and it is complicated by my lack of VF/APEx capability.
We have a quote process that uses custom fields on the quote line item object to define allowed multipliers.
I want to pull the info from these line items into the approval email so that the approver does not have to open the quote to see the line item requirements.
If there is a way to do that using VF/APEX, I would be very appreciative.
Hi I followed the same way you have mentioned but still Opportunity Line Items is coming in Random order and not the Opportunity line item sorted order.
Hi,
all OK it worked for me and been working for a while now.
thanks,
Alex
Here is the Class
public class SortedLineItemsController {
public Opportunity opportunity { get; set; }
public OpportunityLineItem[] getSorted() {
if (opportunity == null || opportunity.opportunityLineItems== null) {
return null;
}
OpportunityLineItem[] result = new OpportunityLineItem[1];
for (OpportunityLineItem item : opportunity.opportunityLineItems) {
result.add(0, item);
}
return result;
}
}
---------------------------
Here is the component
<tr >
<th>Product Name</th><th>Quantity</th><th>Unit Price</th><th>Total Price</th>
</tr>
<SortedLineItemsController value="{!relatedto}"/>
<apex:repeat var="opp" value="{!relatedTo.OpportunityLineItems}">
<tr>
<td> {!opp.PriceBookEntry.name} </td>
<td align="right">{!ROUND(opp.Quantity,0)}</td>
<td align="right">$ {!ROUND(opp.UnitPrice,0)}</td>
<td align="right">$ {!ROUND(opp.TotalPrice,0)}</td>
</tr>
</apex:repeat>
</table>
try this
And :
I tried to change that in the component and getting following error while saving
"Invalid field Product2 for SObject OpportunityLineItem
"
And for the class
instead of :
try querying the DB :
rgds,
Alex
<td>{!li.PriceBookEntry.Product2.Quantity}</td>
<td>${!li.PriceBookEntry.Product2.TotalPrice}</td>
{!oli.PriceBookEntry.Product2.name}
{!oli.PriceBookEntry.Product2.Quantity}
{!oli.PriceBookEntry.Product2.TotalPrice}
<td>{!li.PricebookEntry.Product2.Name}</td>
<td>{!li.Quantity}</td>
<td>${!li.TotalPrice}</td>
</tr>
</apex:repeat>
<!-- Needed to work around limitation that the standard controller cannot "see"
the linkage between the value attribute and the opportunity property -->
<apex:variable var="oli" value="{!value.OpportunityLineItems}" rendered="false">
{!oli.PricebookEntry.Product2.Name}
{!oli.Quantity}
{!oli.TotalPrice}
I need help. How to refer the child object field names in the subject of email template. In this case Opportunity Line item field, can we add in the subject?