1

In my below code, I have an obj1 and obj2 , which is child of Obj1. I am using a visualforce page like below with obj1__c as a standard controller and rendering this page as PDF. I use <apex:relatedList list="obj2__r"/> to show the related list in pdf but I do not want to show the related list using <apex:relatedlist> since I get edit/del option on the pdf page for each related list record. I would like to just show a field( field1__c) of obj2 on the visualforce page. How can I show the field1__c using an output text field or something. Any idea?

    <apex:page standardController="obj1__c" renderAs="PDF">
    <apex:relatedList list="obj2__r"/>

    <apex:pageBlock title="A Title">
      <apex:pageBlockSection columns="1">
      <table border="1" cellpadding="6">
// Gives an error - Could not resolve the entity from <apex:outputField> value binding '{!obj1__c.obj2__r.field1__c}'. <apex:outputField> can only be used with SObjects, or objects that are Visualforce field component resolvable.   
        <apex:outputField value="{!obj1__c.obj2__r.field1__c}"/>
        <apex:outputField value="{!obj1__c.obj2__r.field2__c}"/>
      </table>
      </apex:pageBlockSection>
    </apex:pageBlock>

    </apex:page>

3 Answers 3

2

Just add this style to your page:

.actionColumn { display: none; }

The following works for me:

<apex:page standardController="Account"
    renderAs="pdf" showHeader="false" sidebar="false"
    applyBodyTag="false" applyHtmlTag="false">

    <html>
        <head>            
            <style>.actionColumn { display: none; }</style>
        </head>
        <body>
            <apex:relatedList list="Contacts" />
        </body>
    </html>

</apex:page>
1
  • Still the same for me. Actually I have another pageblock section in my VF page and I am using the related list tag outside this pageblock section. Is it different for custom object?
    – SfdcBat
    Commented May 24, 2016 at 21:33
1

The way it can be done is by creating an extension and query the field of the related list in the extension. For example:

sampleextension:

public class sampleextension{

private obj1 obj1_sample{get;set;}
List<obj1> relatedlist{get;set;}

sampleextension(ApexPages.StandardController controller){
obj1_sample =(obj1)controller.getRecord();
relatedlist=[select id,(select id,field1__c from obj2__r) from obj1 where id=:obj1_sample];
}

Then use the List<obj1> relatedlist in the visualforce page to get the field1__c of the related list object - obj2. Hope it is clear.

0

You can use page block table inside pageblocksection and control the view the way you want. Try something like below,

<apex:page standardController="obj1__c" renderAs="PDF">
<apex:pageBlock title="A Title">
  <apex:pageBlockSection columns="1">
      <apex:pageBlockTable value="{!obj1__c.obj2__r}" var="obj2">
        <apex:column value="{!obj2.field1__c}"/>
        <apex:column value="{!obj2.field1__c}"/>
      </apex:pageBlockTable>
  </apex:pageBlockSection>
</apex:pageBlock>

5
  • I think I would have to query the child relationship in my extension before I use it here in Pageblock table! is that correct?
    – SfdcBat
    Commented May 24, 2016 at 23:52
  • I think it should work without querying, if you are using standard controller. Give it a try. If not working, please add controller extension and query in that.
    – Victor
    Commented May 25, 2016 at 16:01
  • Did not work. We need to query the fields in the child using child relation ship name ( obj2__r)before using it in VF page
    – SfdcBat
    Commented May 25, 2016 at 16:24
  • Okay cool. Now it is displaying correctly right?
    – Victor
    Commented May 25, 2016 at 20:07
  • No actually I had to use apex repeat command! I could not do only with pageblocktable
    – SfdcBat
    Commented May 25, 2016 at 20:16

You must log in to answer this question.

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