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
jordanmjordanm 

Page & custom controller extension: Second child level yields unwanted results

Hello,

I've been working on this PDF page that involves a Grandparent (family object) --> Parent (participant object) --> Child (participant incomes object) relationship.

I finally got a custom controller extension figured out which allows me to go down two child levels (which is illegal using just the standard force.com controller)

but I'm doing something wrong. My family yields all the participants in it just fine, but when I go to pull the participant's income information it is printing all the incomes for all the participants in the family instead of the income only related specifically to each participant.

 

What am I doing wrong?

 

Here is the page:

<apex:page standardController="Family__c" showHeader="false" renderAs="pdf" extensions="UIApplicationEXT">
    <body>
        <apex:stylesheet value="{!URLFOR($Resource.CRTpdf, 'styles.css')}"/>
        <apex:image value="{!URLFOR($Resource.CRTpdf, 'logo.gif')}"/>
        <apex:panelGrid columns="1" styleClass="companyTable" width="100%">
            <apex:outputText value="{!$Organization.Name}" styleClass="companyName"/>
            <apex:outputText value="{!$Organization.Street}"/>
            <apex:outputText value="{!$Organization.City}, {!$Organization.State} {!$Organization.PostalCode}"/>
            <apex:outputText value="{!$Organization.Phone}"/>
        </apex:panelGrid>
        <apex:outputPanel layout="block" styleClass="line"/>
        <apex:panelGrid columns="1" styleClass="centered" width="100%">
            <apex:panelGrid columns="2" width="100%" cellpadding="0" cellspacing="0" columnClasses="left,right">
                <apex:outputText value="Family# {!Family__c.name}"  styleClass="customerName"/>
                <apex:outputField value="{!Family__c.lastmodifieddate}" style="text-align:right"/>
	            <apex:outputText value="Total Family Income: "/>
	            <apex:outputField value="{!Family__c.Family_Income__c}"/>
	            <apex:outputText value="Family Size: "/>
	            <apex:outputField value="{!Family__c.Family_Size__c}"/>
	            <apex:outputText value="Family Type: "/>
	            <apex:outputField value="{!Family__c.Family_Type__c}"/>
            </apex:panelGrid>
        </apex:panelGrid>
        <apex:repeat value="{!Family__c.Family_Households__r}" var="fhh">
	        <apex:outputPanel layout="block" styleClass="lineSmall"/>
	        <apex:outputText value="Address Type: {!fhh.Address__r.Address_Type__c}"/>
	        <apex:panelGrid columns="1" styleClass="centered" width="100%">
	            <apex:outputText value="{!fhh.Address__r.Address_1__c} {!fhh.Address__r.Address_2__c}"/>
	            <apex:outputText value="{!fhh.Address__r.City__c}, {!fhh.Address__r.State__c} {!fhh.Address__r.Zip__c}"/>
	        </apex:panelGrid>
        </apex:repeat>
        <apex:outputPanel layout="block" styleClass="lineSmall"/>
        <apex:repeat value="{!parts}" var="mem">
            <apex:panelGrid columns="2" columnClasses="left,right" width="100%">
                <apex:panelGroup >
                    <apex:outputText value="{!mem.First_Name__c} {!mem.Middle_Name__c} {!mem.Last_Name__c}" styleClass="productName"/>
                    <apex:outputPanel layout="block" styleClass="productDetail">
                        <apex:repeat value="{!partIncomes1}" var="inc">
                            <apex:panelGrid columns="2" columnClasses="left,none">
                           		<apex:outputText value="Income Type: " style="font-weight:bold"/>
                            	<apex:outputField value="{!inc.Income_Type__c}"/>
                            	<apex:outputText value="Annual Income: " style="font-weight:bold"/>
                            	<apex:outputField value="{!inc.Annual_Calculation__c}"/>
                            </apex:panelGrid>
                        </apex:repeat>
                        <apex:panelGrid columns="2" columnClasses="left,none">
                            <apex:outputText value="Social Security Number:" style="font-weight:bold"/>
                            <apex:outputField value="{!mem.Social_Security_Number__c}"/>
                            <apex:outputText value="Gender:" style="font-weight:bold"/>
                            <apex:outputField value="{!mem.Gender__c}"/>
                        </apex:panelGrid>
                    </apex:outputPanel>
                </apex:panelGroup>
				<apex:panelGrid columns="2">
					<apex:outputText value="Total Income: "/>
	                <apex:outputField value="{!mem.Total_Income__c}" styleClass="productName"/>
                </apex:panelGrid>             
            </apex:panelGrid>
        </apex:repeat>
        <apex:outputPanel layout="block" styleClass="line"/>
    </body>
</apex:page>

 Here is the custom controller extension:

public class UIApplicationEXT{

	public Family__c fam {get;set;}
	public id famId {get;set;}
	
	public list<Participant__c> parts {get;set;}
	
	public list<Participant_Income__c> partIncomes1 {get;set;}
	
	public UIApplicationEXT(ApexPages.StandardController controller) {
		
		fam = new Family__c();
		   
		parts = new list<Participant__c>();
		
		list<Participant_Income__c> partIncomes = new list<Participant_Income__c>();
		partIncomes1 = new list<Participant_Income__c>();
		
		famId=system.currentpagereference().getparameters().get('id');
		
		// fetch the values by SOQL on the basis of family id
		parts = [SELECT id,Name,First_Name__c, Last_Name__c,
				Middle_Name__c, Gender__c, Total_Income__c,
				Social_Security_Number__c  
				FROM Participant__c
				WHERE Family__c=:famId]; 
				  
		for(Participant__c parts1:parts)
			{
				// fetch the values by SOQL on the basis of participant id
				partIncomes=[select id,Name,Income_Type__c, Annual_Calculation__c 
							FROM Participant_Income__c
							WHERE Participant__c=:parts1.id];   
				partIncomes1.addall(partIncomes);
			}
	}
}

 Any ideas?