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
xpatxpat 

Child data in visualforce page

Hello,
 
I am new in visualforce
 
I have a visualforce page with standardaccount controller, i saw in the documentation that you can access to child data
but i get an error
 
I want to display on one page account fields and custom object fields
 
<apex:page standardController="Account" id="pageaccountdetails">
<apex:sectionHeader title="Yearly Account Plan"/>
<apex:inputField value="{!account.yearlyplans__r.year__c}"/>
 
yearlyplans is the name I gave for the child relationship between account and my custon object

I try with outputfield and outputext but doesn't work

How can I display on one page custom object fields with the standardcontroller?

Thanks for your help

Pat

 


VisualForceVisualForce

This is alternate solution..

        u can use extension and

Account acc=new Account(); 

public Account getAccount(){

       acc=[select yearlyplans__r.year__c from Account];

return acc;
}
 
xpatxpat

Thanks for your answer, will try

So if I understand you can access to child data and display as a list or table with the standard Controller but you need to build an extension if you want to be able to modify or enter data.

A we have a standard controller for each object (standard or custom) can't we use as controller extension the custom object controller as both objects are linked with the relationship __r?

Pat

xpatxpat
Hello,
 
I resolved my first issue by an controller extension
 
Coupon_Requested__c promo;
public Coupon_Requested__c getpromo() {
return [select id, Name from Coupon_requested__c where Case_pack_status__c= 'Active' and  IsCP__c = 1 and Account__c = :System.currentPageReference().getParameters().get('id')];
}

but now I have another issue
 
If I don't have coupon_requested record for the account I get an error when I load my page
Coupon_Requested__c promo;
public Coupon_Requested__c getpromo() {
return [select id, Name from Coupon_requested__c where Case_pack_status__c= 'Active' and  IsCP__c = 1 and Account__c = :System.currentPageReference().getParameters().get('id')];
}
System.QueryException: List has no rows for assignment to SObject

Thanks for your help
 
Pat
 
xpatxpat

I fixed it, but not  in a clean way but it works. will see if I can find something better later

public Coupon_requested__c getpromo() {
for (Coupon_requested__c a : [select Name from Coupon_requested__c where Case_pack_status__c= 'Active' and  IsCP__c = 1 and     Account__c = :System.currentPageReference().getParameters().get('id')]){ 
    return a;
}
return null;
}

In my Page I have an outfield so I could not use list