How to fetch child records from parent in SOQL in controller in Salesforce?

Sample Code:

Visualforce page:

<apex:page controller="Sample" sidebar="false">
<apex:form >
    <apex:pageBlock >
        <apex:pageblockTable value="{!memb}" var="m">
            <apex:column value="{!m.Name}"/>
        <apex:pageblockTable value="{!interst}" var="i">
            <apex:column value="{!i.Name}"/>

Apex Controller:

public class Sample
    public List<Member__c>  memb { get; set; }
    public List<Interest__c>  interst { get; set; }
    public sample()
       List<Interest__c> temp = new List<Interest__c>();
       memb = [SELECT Name, (SELECT Name from Interest__r) from Member__c];
       for(Member__c m : memb)
           System.debug('Interests are ' + m.Interest__r);
           for(Interest__c i : m.Interest__r)
               System.debug('Interest is ' + i);
       interst = temp;           


No comments:

Post a Comment

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

submit to reddit