Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
public class MyController { Public List <Account> getAcc (){ List <Account> Acc = [SELECT Id, Name,( SELECT Name, Email FROM Contacts ) FROM Account]; return Acc ; } }
<apex:page Controller="MyController"> <apex:form > <apex:sectionHeader title="Account, Cases and Comments" /> <apex:pageBlock id="list"> <table class="list" border="1" cellpadding="0" cellspacing="0"> <tr class="headerRow"> <th >Account</th> <th colspan="3">Contact</th> </tr> <apex:repeat value="{!Acc}" var="A"> <tr colspan="1"> <td colspan="1"> <apex:outputField style="width:80%" value="{!A.Name}" /> </td> <td> </td> </tr> <apex:repeat value="{!A.Contacts}" var="con"> <tr> <td> </td> <td style="font-weight:bold"> Name </td> <td style="font-weight:bold"> Email </td> </tr> <tr> <td> </td> <td> <apex:outputField style="width:80%" value="{!con.Name}"/> </td> <td> <apex:outputField value="{!con.Email}"/> </td> <td> </td> </tr> </apex:repeat> <tr> <td> </td> <td> </td> <td colspan="2"> </td> </tr> <tr> <td colspan="4" style="border-bottom: black 1px solid;"> </td> </tr> </apex:repeat> <tr> <td> </td> <td colspan="3"> </td> </tr> </table> </apex:pageBlock> </apex:form> </apex:page>
<apex:page Controller="MyController" tabstyle="Account"> <apex:sectionHeader title="Account and child Contacts" subtitle="Account Details" /> <apex:pageBlock > <table class="list" border="1" cellpadding="0" cellspacing="0"> <tr class="headerRow"> <th >Account</th> <th colspan="2">Contact</th> </tr> <apex:repeat value="{!Acc}" var="A"> <tr colspan="1"> <td colspan="1"> <apex:outputField style="width:80%" value="{!A.Name}" /> </td> <td> <apex:repeat value="{!A.Contacts}" var="con"> <table class="list" border="1" cellpadding="0" cellspacing="0" > <tr class="headerRow"> <td style="font-weight:bold"> Name </td> <td style="font-weight:bold"> Email </td> </tr> <tr> <td> <apex:outputField style="width:80%" value="{!con.Name}"/> </td> <td> <apex:outputField value="{!con.Email}"/> </td> </tr> </table> </apex:repeat> </td> </tr> </apex:repeat> </table> </apex:pageBlock> </apex:page>
Use this,
Controller: Visualforce Page:
Please mark this as Best Answer if it helps you!
Thanks!
Try with this one , it will give you the same output as shown in screenshot.
You can use the same controller created by saurabh.
Visualforce Page: