Displaying child record from parent in Salesforce

Sample Code:

Visualforce page:

<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 Controller:

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);


No comments:

Post a Comment

Sharing is Caring!!! Share this with your friends!!!

submit to reddit