Retrieving child record from parent record in Salesforce

Retrieving child record from parent record in Salesforce

Visualforce page:

<apex:page controller=”sample”>
    <apex:pageBlock >
       <apex:pageBlockTable value=”{!mem}” var=”m”>
            <apex:column value=”{!m.Name}”/>
            <apex:repeat value=”{!m.Interest__r}” var=”i”>
                <apex:column value=”{!i.Name}”/>
            </apex:repeat>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>



Apex Controller:


public class sample
{   
    public List<Member__c> mem {get;set;}
    public sample()
    {
        String soql = ‘SELECT Name, (SELECT Name FROM Interest__r) FROM Member__c LIMIT 5’;
        mem = Database.Query(soql);
    }   
}




Output:


Leave a Reply