SOQL Scenario -4
Fetch the records Parent records from Child Object
public class SoqlQuery4 {
public List<Contact> con{set;get;}
public SoqlQuery4(){
con=[select id, lastname, firstname, Account.name, Account.phone from contact];
}
}
<apex:page controller="SoqlQuery4" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!con}" var="c">
<apex:column headerValue="Con Name" value="{!c.lastname}" />
<apex:column headerValue="Con Fname" value="{!c.firstname}" />
<apex:column headerValue="Acc Name" value="{!c.Account.Name}" />
<apex:column headerValue="Acc Phone" value="{!c.Account.phone}" />
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
public class SoqlQuery4 {
public List<Contact> con{set;get;}
public SoqlQuery4(){
con=[select id, lastname, firstname, Account.name, Account.phone from contact];
}
}
<apex:page controller="SoqlQuery4" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!con}" var="c">
<apex:column headerValue="Con Name" value="{!c.lastname}" />
<apex:column headerValue="Con Fname" value="{!c.firstname}" />
<apex:column headerValue="Acc Name" value="{!c.Account.Name}" />
<apex:column headerValue="Acc Phone" value="{!c.Account.phone}" />
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Comments
Post a Comment