function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Denis O'LearyDenis O'Leary 

Render Page As PDF

Hi,

I'm trying to view a custom salesforce object as a PDF. I've an object that has object Line Items (Not too dissimalar to Opportunity -> Opportunity Products set up) I want to print the custom object with the line items attached but can't seem to see how to do this.

This works on the Opportunity object for printing the list of opporunity products on to a table-> 
<apex:repeat var="lineitem" value="{!opportunity.OpportunityLineItems}"> 

but when I try this on my custom object <apex:repeat var="lineitem" value="{!Estimate__c.Estimate_Product_Line_Item__c}"> 
I get an error "Invalid Field Estimate_Product_Line_Item__c for SObject Estimate__c"

There is a master detail relationship between my objects Estimate and Estimate products

Can any one help with something that might get me off the ground on this? 
Best Answer chosen by Denis O'Leary
Diego GutierrezDiego Gutierrez
Have you tried using <apex:relatedList>?? Here it is the documentation: https://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_relatedList.htm

All Answers

Diego GutierrezDiego Gutierrez
Hi Denis, 

Have you tried <apex:repeat var="lineitem" value="{!Estimate__r.Estimate_Product_Line_Item__c}"> ?? 

Diego
Denis O'LearyDenis O'Leary
Yes, I tried this already but I still get an error "Unknown property Estimate__cStandardController.Estimate__r"
Diego GutierrezDiego Gutierrez

ok... and this one (I got the idea from https://developer.salesforce.com/forums/ForumsMain?id=906F000000097MqIAI)


 <apex:repeat var="lineitem" value="{!Estimate__c.Estimate_Product_Line_Item__r}">

If it doesn´t work, could you share your code (or at least the most representative parts?
Denis O'LearyDenis O'Leary
<apex:page standardController="Estimate__c" renderAs="pdf">
 
    
<table class="tables" cellpadding="6" cellspacing="0" width="100%" styleclass="subheader">
    <tr class="subheader"><td>Description</td>
        <td align="right">Quantity</td>
        <td align="right">Make/Model</td>
        <td align="center">Root</td>
        <td align="right">Price</td></tr>
<tr>
</tr>     
<apex:repeat var="lineitem" value="{!Estimate_Product_line_Items}">        
<tr>
<td align="left" width="20%" class="subheader">{!lineitem.Comments__c}</td>
<td align="center" class="subheader">{!lineitem.Quantity__c}</td>    
<td align="right" class="subheader"><apex:outputfield value="{!lineitem.Estimate_Product__c}" /></td>
<td align="right" class="subheader"><apex:outputfield value="{!lineitem.Root__c}" /></td>
<td align="right" class="subheader"><apex:outputfield value="{!lineitem.Price__c}" /></td>
</tr>
</apex:repeat>
<tr><td class="invisiblecell"></td><td colspan="3" class="subheader">Order Total</td><td class="subtext" align="right">
    <apex:outputfield value="{!opportunity.Total_Sales_INDincl__c}"/></td></tr>
</table>    
</apex:page>
Diego GutierrezDiego Gutierrez
ok, one question... Why don´t you start the other way around, I mean, trying to start from the child and go to the Master object? Something like this: 


<apex:page standardController="Estimate_Product_line_Item__c" renderAs="pdf">
 
    
<table class="tables" cellpadding="6" cellspacing="0" width="100%" styleclass="subheader">
    <tr class="subheader"><td>Description</td>
        <td align="right">Quantity</td>
        <td align="right">Make/Model</td>
        <td align="center">Root</td>
        <td align="right">Price</td></tr>
<tr>
</tr>     
<apex:repeat var="lineitem" value="{!Estimate_Product_line_Item__c}">        
<tr>
<td align="left" width="20%" class="subheader">{!lineitem.Comments__c}</td>
<td align="center" class="subheader">{!lineitem.Quantity__c}</td>    
<td align="right" class="subheader"><apex:outputfield value="{!lineitem.Estimate_Product__c}" /></td>
<td align="right" class="subheader"><apex:outputfield value="{!lineitem.Root__c}" /></td>
<td align="right" class="subheader"><apex:outputfield value="{!lineitem.Price__c}" /></td>
</tr>
</apex:repeat>
<tr><td class="invisiblecell"></td><td colspan="3" class="subheader">Order Total</td><td class="subtext" align="right">
    <apex:outputfield value="{!Estimate_Product_line_Item__r.Opportunity.Total_Sales_INDincl__c}"/></td></tr>
</table>    
</apex:page>

I think it should work for what you are requesting, doesn't it?

 
Denis O'LearyDenis O'Leary
I think this will only print out one product line rather than all the lines associated with an Estimate
Diego GutierrezDiego Gutierrez
Have you tried using <apex:relatedList>?? Here it is the documentation: https://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_relatedList.htm
This was selected as the best answer