You need to sign in to do that
Don't have an account?
Don Pierce
Problem displaying list from Apex Class in emailtemplate
I created a simple Apex Class and VFC to display my query results in an email template.
The only thing it displays is the correct size of the list and a blank POId . No List results.
*********************Apex Code
global class POComponent
{
global string POId
{
get;
set;
}
global integer leng
{
get;
set;
}
global List<rstk__poline__c> RSNPOLine2
{
get;
set;
}
public POComponent()
{
POComponentCore();
}
public List<rstk__poline__c> POComponentCore()
{
POId = ApexPages.currentPage().getParameters().get('id');
List<rstk__poline__c> RSNPOLine2 = new List<rstk__poline__c>();
RSNPOLine2 = [SELECT rstk__poline_lne__c,rstk__poline_item__c, rstk__poline_descr__c FROM rstk__poline__c where rstk__poline_ordno__c = :POId];
leng = RSNPOLine2.size();
return RSNPOLine2;
}
}
*************************VFC code:
<apex:component controller="POComponent" access="global">
<apex:attribute name="configproducts" description="DCPId" type="String" assignTo="{!POId}"/>
<table>
<apex:repeat var="arr" value="{!RSNPOLine2}">
<tr>
<td style="width: 010mm; height: 004mm;">Just a test inside VFC</td>
<td style="width: 025mm; height: 004mm;">
<div style="width: 100%; max-width:100%; white-space: nowrap; overflow: hidden;">{!arr.rstk__poline_descr__c}</div>
</td>
<td style="width: 067mm; height: 004mm; ">
<div style="width: 100%; max-width:100%; white-space: nowrap; overflow: hidden;">{!arr.rstk__poline_item__c}</div>
</td>
<td style="width: 010mm; height: 004mm;">
<div style="width: 100%; max-width:100%; white-space: nowrap; overflow: hidden; text-align: right;">{!arr.rstk__poline_lne__c}</div>
</td>
<td style="width: 010mm; height: 004mm; ">
<div style="width: 100%; max-width:100%; white-space: nowrap; overflow: hidden; text-align: left; margin-left: 1mm;">CCCCC</div>
</td>
<td style="width: 025mm; height: 004mm;">
<div style="width: 100%; max-width:100%; white-space: nowrap; overflow: hidden; text-align: right;">1111.99</div>
</td>
</tr>
</apex:repeat>
</table>
<table>
<tr><td>This is outside the repeat loop, list size = {!leng} and POId is {!POId}</td></tr></table>
</apex:component>
******************Email Template code:
<messaging:emailTemplate subject="Purchase Order" recipientType="User" relatedToType="rstk__PO_Print_Header__c">
<messaging:htmlEmailBody >
<html>
<head>
<style type="text/css" media="print">
@page {
size:A4;
margin-left: 0.8cm;
margin-right: 0.8cm;
margin-top: 12.0cm;
margin-bottom: 4.5cm;
@top-center {
content: element(header);
}
@bottom-left {
content: element(footer);
}
}
</style>
</head>
<body>
<c:POComponent configproducts="{!relatedTo.Id}"/>
</body>
</html>
</messaging:htmlEmailBody>
</messaging:emailTemplate>
The only thing it displays is the correct size of the list and a blank POId . No List results.
*********************Apex Code
global class POComponent
{
global string POId
{
get;
set;
}
global integer leng
{
get;
set;
}
global List<rstk__poline__c> RSNPOLine2
{
get;
set;
}
public POComponent()
{
POComponentCore();
}
public List<rstk__poline__c> POComponentCore()
{
POId = ApexPages.currentPage().getParameters().get('id');
List<rstk__poline__c> RSNPOLine2 = new List<rstk__poline__c>();
RSNPOLine2 = [SELECT rstk__poline_lne__c,rstk__poline_item__c, rstk__poline_descr__c FROM rstk__poline__c where rstk__poline_ordno__c = :POId];
leng = RSNPOLine2.size();
return RSNPOLine2;
}
}
*************************VFC code:
<apex:component controller="POComponent" access="global">
<apex:attribute name="configproducts" description="DCPId" type="String" assignTo="{!POId}"/>
<table>
<apex:repeat var="arr" value="{!RSNPOLine2}">
<tr>
<td style="width: 010mm; height: 004mm;">Just a test inside VFC</td>
<td style="width: 025mm; height: 004mm;">
<div style="width: 100%; max-width:100%; white-space: nowrap; overflow: hidden;">{!arr.rstk__poline_descr__c}</div>
</td>
<td style="width: 067mm; height: 004mm; ">
<div style="width: 100%; max-width:100%; white-space: nowrap; overflow: hidden;">{!arr.rstk__poline_item__c}</div>
</td>
<td style="width: 010mm; height: 004mm;">
<div style="width: 100%; max-width:100%; white-space: nowrap; overflow: hidden; text-align: right;">{!arr.rstk__poline_lne__c}</div>
</td>
<td style="width: 010mm; height: 004mm; ">
<div style="width: 100%; max-width:100%; white-space: nowrap; overflow: hidden; text-align: left; margin-left: 1mm;">CCCCC</div>
</td>
<td style="width: 025mm; height: 004mm;">
<div style="width: 100%; max-width:100%; white-space: nowrap; overflow: hidden; text-align: right;">1111.99</div>
</td>
</tr>
</apex:repeat>
</table>
<table>
<tr><td>This is outside the repeat loop, list size = {!leng} and POId is {!POId}</td></tr></table>
</apex:component>
******************Email Template code:
<messaging:emailTemplate subject="Purchase Order" recipientType="User" relatedToType="rstk__PO_Print_Header__c">
<messaging:htmlEmailBody >
<html>
<head>
<style type="text/css" media="print">
@page {
size:A4;
margin-left: 0.8cm;
margin-right: 0.8cm;
margin-top: 12.0cm;
margin-bottom: 4.5cm;
@top-center {
content: element(header);
}
@bottom-left {
content: element(footer);
}
}
</style>
</head>
<body>
<c:POComponent configproducts="{!relatedTo.Id}"/>
</body>
</html>
</messaging:htmlEmailBody>
</messaging:emailTemplate>
Please use this apex code,
Explanation : for Visualforce component there is no as such use of constructor. Developer need to create get methods.
--PS
All Answers
your relatedToType is rstk__PO_Print_Header__c and you are using the Id of that object. But you ar quering it from the rstk__poline__c object. This is the reason you are getting blank records.
Thanks
Prosenjit
<messaging:emailTemplate subject="Purchase Order" recipientType="User" relatedToType="rstk__poline__c">
But still have the same problem. The only thing that is displayed when rendered is shown below.
Both the POId and size are correct values so I know it is pulling the data I need(in apex class):
____
This is before the repeat loop, list size = 16 and POId is a8q0U0000004D2DQAU
This is outside the repeat loop, list size = 16 and POId is a8q0U0000004D2DQAU
____
Please use this apex code,
Explanation : for Visualforce component there is no as such use of constructor. Developer need to create get methods.
--PS
Thats normal. Just comment the whole VF component and save. Next paste the whole apex code and try. It was happened because I changed the code.
--PS
1. Comment the whole Visualforce component and save.
2. Paste the EXACT apex code that I have provided and save.
3. Uncomment the whole Visualforce Page and save.
4. Test your requirement.
5. If it is okay mark my reply as Best Answer ;)
6. If it is not okay let me know
--PS