+ 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

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}"/>