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
Kiran Kumar 77Kiran Kumar 77 

How to retrive the Contact records which are releted to account in pagination

I have on requirement :
I want to retrive the contact records which are related to account, I wrote standardset controller but i am uanable to display the records i Visualforce Page
Can you please help me;
<apex:page controller="TrAccountrelatedContacrs">
  <apex:form >
      <apex:pageBlock >
          <apex:pageBlockSection >
              <apex:pageBlockTable value="{!conList}" var="i">
                  <apex:column value="{!i.cat.Name}"/>
              </apex:pageBlockTable>
              <!--<apex:pageBlockTable value="{!cont}" var="co">
                  <apex:column value="{!co.name}"/>
              </apex:pageBlockTable>-->
          </apex:pageBlockSection>
      </apex:pageBlock>
     
  </apex:form>
</apex:page>
----------------------------------------------------------------
Controlller:
public class TrAccountrelatedContacrs {
    public List<AccountWrapper>  conList = new List<AccountWrapper>();
    //List<Account> conList {get;set;}
   
    public ApexPages.StandardSetController con {
        get{
            if(con==null){
                con = new ApexPages.StandardSetController(Database.getQueryLocator([select id, Account.name,(select Name,Contact.FirstName,Contact.LastName from account.Contacts) from Account limit 100]));
                system.debug('############'+con);
                con.setPagesize(10);
            }
            return con;
        }
        set;
    }
    public List<AccountWrapper> getconList(){
        conList = new List<AccountWrapper>();
        for(Account e : (List<Account>)con.getRecords())
            conList.add(new AccountWrapper(e));// 
        return conList;
    }
    public Boolean hasNext {
        get{
            return con.getHasNext();
        }
        set;
    }
    public Boolean hasPrevious{
        get{
            return con.getHasPrevious();           
    }
    set;
    }
    public Integer PageNumber{
        get{
            return con.getPageNumber();
        }
        set;
    }
    public void first(){
        con.first();
    }
    public void last(){
        con.last();
    }
    public void previous(){
        con.previous();
    }
    public void next(){
        con.next();
    }
    public void cancel(){
        con.cancel();
    }
   
    public class AccountWrapper {
        public boolean checked {get;set;}
        public Account cat {get;set;}
        public AccountWrapper(){
            cat = new Account();
            checked = false;
        }
        public AccountWrapper(Account c){
          cat =c;
          checked = false;
        }
    }
    public class ContactWrapper{
        public contact cont {get;set;}
        public ContactWrapper(contact e){
           cont = new contact();
        }
    }

}

Thanks in Advance

Tony TannousTony Tannous
Dear Kiran,

try to put this in the VF 


<apex:page controller="TrAccountrelatedContacrs">
  <apex:form >
      <apex:pageBlock >
          <apex:pageBlockSection >
              <apex:pageBlockTable value="{!conList}" var="i" >
                  <apex:column value="{!i.cat.Name}"/>
                  <apex:column >
                  <table  width="100%">
                 
                  <apex:repeat value="{!i.cat.Contacts}" var="ContactSelec">
                  <tr><td>{!ContactSelec.FirstName}</td> <td>{!ContactSelec.LastName }</td></tr>
                  </apex:repeat>
                  </table>
               </apex:column>
              </apex:pageBlockTable>
            
          </apex:pageBlockSection>
      </apex:pageBlock>
    
  </apex:form>
</apex:page>

Regards
Kiran Kumar 77Kiran Kumar 77
related List

In this Account related list contains only perticular contact is coming
Like this way i need to show isthere any way to do this?
Tony TannousTony Tannous
You need only to see the contact related to a specific account??
and not to see all the account and the contact related?

Kiran Kumar 77Kiran Kumar 77
Hi Tony Tanous,  Thanks for giving replay .
I need to display Account detaild page which is showing its related contacts
Tony TannousTony Tannous
Kiran,

you can try this code, and if you want you can simply remove the tabs

<apex:page standardController="Account" showHeader="false" tabStyle="account" >
<style>
.activeTab {background-color: #236FBD; color:white;
background-image:none}
.inactiveTab { background-color: lightgrey; color:black;
background-image:none}
</style>
<apex:tabPanel switchType="client" selectedTab="tabdetails" id="AccountTabPanel" tabClass="activeTab" inactiveTabClass="inactiveTab">
<apex:tab label="Details" name="AccDetails" id="tabdetails">
<apex:detail relatedList="false" title="true" inlineEdit="true"/>
</apex:tab>
<apex:tab label="Contacts" name="Contacts" id="tabContact">
<apex:relatedList subject="{!account}" list="contacts" />
</apex:tab>

</apex:tabPanel>
</apex:page>

and while calling you VF page you create you need to pass as parameter  the compte id  ex :/apex/tabbedAccount?id=001i0000005x5YY.
 
Good Luck