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
Prakash Kumar Mikkilineni 1Prakash Kumar Mikkilineni 1 

how to retrieve the account related contacts by using parent child relationship soql query and create vf page to dispaly the records

SFDC_SaurabhSFDC_Saurabh
public class sample
{   
    public List<Account> acct {get;set;}
    public sample()
    {
        String soql = 'SELECT Name, (SELECT Name, Email FROM Contacts) FROM Account LIMIT 5';
        acct = Database.Query(soql);
    }   
}
 
<apex:page controller="sample">
    <apex:pageBlock >
        <apex:pageBlockTable value="{!acct}" var="a">
            <apex:column value="{!a.Name}"/>
            <apex:repeat value="{!a.Contacts}" var="c">
                <apex:column value="{!c.Name}"/>
            </apex:repeat>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>