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
Uday MenkurkarUday Menkurkar 

Unable to get Custom Object List Extension Controller working

Question for VF/Apex experts.

I'm unable to load child records from a master-detail relationship using Apex and Visualforce.  Here is my setup.  I've Master-Detail relationship between PP_Deals__c (Master object) and Tranche__c (Child object).  My goal is to display parent-child records meeting certain criteria using VF page and a custom list controller.  My sample VF page and Apex extension controller is below.  The problem is that I can see the parent records but no child records.  If I remove the WHERE clause in the query, I can see all the records.  Also, if I put a specific parent id in the parent clause I can see records, but in its current form it I don't see child records when in principal the WHERE clause should have the correct id.  What am I missing?

Thanks in advance for help.

<!-- Visualforce code -->
<apex:page standardController="PP_Deals__c" recordSetVar="deals" extensions="extCon">
    <apex:pageBlock >
        <apex:pageBlockTable value="{! deals }" var="ds">
            <apex:column value="{! ds.Name }"/>
            <apex:column value="{! ds.id }"/>

            <apex:column >            
                <apex:pageBlock >
                    <apex:pageBlockTable value="{! relatedTranches}" var="val">
                        <apex:column value="{! val.name}"/>
                        <apex:column value="{! val.Id}"/>
                    </apex:pageBlockTable>
                </apex:pageBlock>
            </apex:column>
            
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

//  Associated Apex Code -- Controller List extension
public class extCon {   
    private final PP_Deals__c deal;
    
    public extCon(ApexPages.StandardSetController controller) {
        deal = (PP_Deals__c) controller.getRecord();
    }
    
    public List<Tranche__c> getrelatedTranches()
    {
        List <Tranche__c> conList = New List<Tranche__c>();
        
        for(PP_Deals__c acc:[ SELECT id,name, (SELECT id, name FROM Tranches__r) FROM PP_Deals__c WHERE id = :deal.id ])
        {
           for(Tranche__c con:acc.Tranches__r)
               conList.add(con);
        }

        return conList;
    }
}
Best Answer chosen by Uday Menkurkar
Amit Chaudhary 8Amit Chaudhary 8
Try to update your VF page like below
<apex:page standardController="PP_Deals__c" recordSetVar="deals" extensions="extCon">
    <apex:pageBlock >
        <apex:pageBlockTable value="{! deals }" var="ds">
            <apex:column value="{! ds.Name }"/>
            <apex:column value="{! ds.id }"/>

            <apex:column >            
                <apex:pageBlock >
                    <apex:pageBlockTable value="{!ds.Tranches__r}" var="val">
                        <apex:column value="{! val.name}"/>
                        <apex:column value="{! val.Id}"/>
                    </apex:pageBlockTable>
                </apex:pageBlock>
            </apex:column>
            
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

Let us know if this will help you
 

All Answers

Glyn Anderson 3Glyn Anderson 3
Your constructor should take an ApexPages.StandardController.  You can instantiate your own StandardSetController from a query locator if you need to.
Amit Chaudhary 8Amit Chaudhary 8
Try to update your VF page like below
<apex:page standardController="PP_Deals__c" recordSetVar="deals" extensions="extCon">
    <apex:pageBlock >
        <apex:pageBlockTable value="{! deals }" var="ds">
            <apex:column value="{! ds.Name }"/>
            <apex:column value="{! ds.id }"/>

            <apex:column >            
                <apex:pageBlock >
                    <apex:pageBlockTable value="{!ds.Tranches__r}" var="val">
                        <apex:column value="{! val.name}"/>
                        <apex:column value="{! val.Id}"/>
                    </apex:pageBlockTable>
                </apex:pageBlock>
            </apex:column>
            
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

Let us know if this will help you
 
This was selected as the best answer
Uday MenkurkarUday Menkurkar
Yes, it worked.  Boss, You are the BEST!!  Much appreciated.