Tuesday, March 12, 2013

Displaying records of Accounts with Contacts in VF Page


Visualforce Page:

<apex:page controller="accountswthcon" >
    <apex:form >
    <table>
        <apex:repeat value="{!items}" var="a">
        <tr>
            <td>
            {!a.name}  
            </td>
            <td>
            <apex:repeat value="{!a.contacts}" var="c">
                {!c.lastname}<br/>
            </apex:repeat>
            </td>     
        </tr>
        </apex:repeat>
    </table>     
    </apex:form>
</apex:page>

Apex Class:

public with sharing class accountswthcon {
   
    public List<Account> items{get; set;}

    public accountswthcon(){
        items=[Select id, name, (select lastname from Contacts) from Account];
                                        }
                                                                }

No comments:

Post a Comment