function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sfdc freshersfdc fresher 

I want display the list of Contacts of particualr account in VF page

select id,name,(select FirstName,LastName from Contacts) from Account.

this query will give the Account, along with corresponindg contacts. I want to disply the particular Contact along with Account in VF please, could anyone please help.
And I want to disply the Account which has the contacts only..some account have dont have contact associated with them. How to achieve this.. could anyone please guide me
Ashif KhanAshif Khan
Hi

AccountCont.vfp
 
<apex:page controller="AccClass" tabstyle="account" sidebar="false">
    <apex:pageBlock >
        <apex:repeat value="{!Accounts}" var="a">
            <apex:pageBlockSection title="{!a.name}"></apex:pageBlockSection>
            <apex:pageBlockTable value="{!a.Contacts}" var="item">
                <apex:column value="{!item.FirstName}"/>
                <apex:column value="{!item.LastName}"/>
            </apex:pageBlockTable>
        </apex:repeat>      
    </apex:pageBlock>
</apex:page>

AccClass.apxc
 
public class AccClass {

    public List<Account> getAccounts(){
        return [select id,name,(select FirstName,LastName from Contacts) from Account where id in (select accountid from contact where accountid!=null )];
    }
    
    
}

I hope this is the solution of your question

Regards
Ashif 
mukesh guptamukesh gupta
Hi,
First you need to create visualforce page: - contactsList
<apex:page controller="contactLists">
    <apex:pageBlock >
        <apex:repeat value="{!Accounts}" var="acc">
            <apex:pageBlockSection title="{!acc.name}"></apex:pageBlockSection>
            <apex:pageBlockTable value="{!acc.Contacts}" var="cont">
                <apex:column value="{!cont.FirstName}"/>
                <apex:column value="{!cont.LastName}"/>
            </apex:pageBlockTable>
        </apex:repeat>      
    </apex:pageBlock>
</apex:page>

apex controller:- contactLists 
 
public class contactLists {

        public List<Account> getAccounts(){
        return [select id,name,(select id, FirstName,LastName from Contacts) from Account where id in (select accountid from contact where accountid!=null )];
    }

}

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh