+ Start a Discussion
Trevor ViallTrevor Viall 

Can't seem to get child object to work on standard controller

So, I'm trying to get product related to opportunity to show up in the same page, but even with an extended controller I can't seem to get it working. 

<apex:page standardController="Opportunity" extensions="PositionsExtends">
    <apex:form >
        <apex:pageBlock title="Edit Opportunity" mode="edit">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="Opportunity Fields" Columns="1">
                <apex:outputText value="{!Opportunity.Amount}"/>
                <apex:inputField value="{!Opportunity.AccountId}"/>
                <apex:inputField value="{!Opportunity.LeadSource}"/>
                <apex:inputField value="{!Opportunity.CloseDate}"/>
                <apex:inputField value="{!Opportunity.StageName}"/>
            </apex:pageBlockSection>
            
            <apex:pageBlockSection>
                <apex:outputField value="{!ProductList.Name}"/>
                <apex:outputField value="{!ProductList.Opportunity__c}"/>
                <apex:outputField value="{!ProductList.StockKeepingUnit}"/>
                <apex:outputField value="{!ProductList.IsActive}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>


public class PositionsExtends {
    
    public List<Product2> ProductList {get;set;}
    
    public PositionsExtends(apexpages.StandardController stdcontroller) {
        ProductList= [SELECT Name, Opportunity__c, StockKeepingUnit, IsActive FROM Product2 Limit 100];
    }
}


What am I doing wrong here I am just getting an error saying Unknown property 'OpportunityStandardController.Product2'
SFDC_SaurabhSFDC_Saurabh
A person other day had similar query.
Please refer to my reply in that post. See if this helps you :
https://developer.salesforce.com/forums?id=9062I000000IPqGQAW
RajandraSRajandraS
Hi,
Check this for getting child object details.
<apex:page standardController="Site_Visit1__c" extensions="extendSiteVisit" recordSetVar="sites">
<apex:pageBlock >
<apex:pageBlockTable var="s" value="{!sites}">
<apex:column headerValue="Name of Visit" >
<apex:outputField value="{! s.Name}"/>
</apex:column>
<apex:column headerValue="Date of Visit">
<apex:outputField value="{! s.Time_and_Date__c}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>

public class extendSiteVisit {
public List<Site_Visit1__c> sites{get; set;}
public Opportunity Site_Visit1__c{get; set;}

        public extendSiteVisit(ApexPages.StandardSetController controller) {
                currentRecord = [SELECT Id, Name, contact__c FROM site_visit1__c WHERE Id = :ApexPages.currentPage().getParameters().get('id')]; // this will return current record object(child) detail from that you can use parent Id (here contact is parent so contact__c)
                
         sites = [SELECT id, Time_and_Date__c, name, contact__c FROM site_visit1__c WHERE conact__c=:currentRecord.accountId];
        }

}