Retrieve Child Record From Parent Record using Apex #inSalesforce
Suppose here Parent is Contact and the Child is Favorite.
Class:
public class chFrPa{
public List<Contact> cList {get;set;}
public chFrPa(){
cList = [SELECT Id, Name, (SELECT Id, Name FROM Favorites__r) FROM Contact LIMIT 100];
}
}
public List<Contact> cList {get;set;}
public chFrPa(){
cList = [SELECT Id, Name, (SELECT Id, Name FROM Favorites__r) FROM Contact LIMIT 100];
}
}
Page:
<apex:page controller="chFrPa">
<table>
<apex:repeat value="{!cList}" var="cont">
<tr>
<td><apex:outputText value="{!cont.Id}" label="Contact Id"/></td>
<td><apex:outputText value="{!cont.Name}" label="Contact Name"/></td>
<apex:repeat value="{!cont.Favorites__r}" var="fav">
<td><apex:outputText value="{!fav.Id}" label="Favorite Id"/></td>
<td><apex:outputText value="{!fav.Name}" label="Favorite Name"/></td>
</apex:repeat>
</tr>
</apex:repeat>
</table>
</apex:page>
<table>
<apex:repeat value="{!cList}" var="cont">
<tr>
<td><apex:outputText value="{!cont.Id}" label="Contact Id"/></td>
<td><apex:outputText value="{!cont.Name}" label="Contact Name"/></td>
<apex:repeat value="{!cont.Favorites__r}" var="fav">
<td><apex:outputText value="{!fav.Id}" label="Favorite Id"/></td>
<td><apex:outputText value="{!fav.Name}" label="Favorite Name"/></td>
</apex:repeat>
</tr>
</apex:repeat>
</table>
</apex:page>
Comments
Post a Comment