+ Start a Discussion

display child object fields on a visulaforcepage with parents standard controller

Hi all, 


how can I show related list records on a VF page where the standardcontroller is on the Parents object. 


I have to create a report that will be rendered as a pdf when someone click the "Generate PDF" button. For this I need to create the VF on Parents obejcts. But how can I show my Line Items (which is the related list records) on the VF?




Try this type of vf code.
<apex:page standardController="Parent__c" renderAs="pdf">
<apex:relatedList list="Child__r" />

No that doesn't work. I'm not trying to display a related list but actually pick and choose some fields along with the fields from Parents to make a custom report that will then render as a report and save it on the attachment. 


I believe I will have to write a SOQL query to fetch all the child records and display it on the report but thanks anyway. 


This is my entire apex code



public with sharing class CompareNames2 {

     private final Documentum__c doc;
    public String getLabel() {
           string label;
           string CustomFirstName;
           string CustomLastName;
           List<String> lstName = doc.Name.split(',');
           CustomLastName = lstName[0];
           if(lstName.size() > 1)
               CustomFirstName = lstName[1];
           doc.CustomName__c = CustomFirstName +' '+ CustomLastName;
           String AccNm;

            if(label == null || label == '')
                Account accountName;
                Contact contactName;
                if(doc.Account__c != null){     //I assume name of relation of account is Account__c
                    accountName = [Select Id, First_Name__c, Last_Name__c, Name from Account where Id =: doc.Account__c];
                    AccNm = (String)accountName.Name;
                if(doc.Contact__c != null){     //I assume name of relation of contact is Contact__c
                    contactName = [Select Id, FirstName, LastName, Name from Contact where Id =: doc.Contact__c];
                if(AccNm != doc.CustomName__c)
                    label = CustomLastName + '/' + accountName.Name;
                }else if(accountName.Name == doc.CustomName__c)
                    label = doc.Name;
}catch(System.Exception e){
    System.debug('Exception occured: ' + e);
}                    return label;       
    public String getInitial(){
        string initial;
        if(initial == null || initial == '')
            User userName;
            if(doc.Initials__c != null){
                userName = [Select Id, FirstName, LastName, Name from User where Id =: doc.Initials__c];
                initial = userName.FirstName.SubString(0,1) + '.' + userName.LastName.SubString(0,1)+ '.';
        return initial;
    private void setLabel(){}
    private void setInitial(){}
    public CompareNames2(ApexPages.StandardController controller) {
        this.doc = (Documentum__c)Controller.getRecord();