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
veeru417veeru417 

How to group contacts by their appropriate account ?Output Should be in pageblocktables?

grouping contacts by their appropriate account and the output should be in pageblocktable.I have seen one code which will display in datatable but i want the code for pageblocktable.

Can anyone help me 

 

Regards,

veer


Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

A simple task that requires just three easy steps:

 

1) Query the accounts and contacts:

 

... = [SELECT Id,Name,(SELECT Id,Name FROM Contacts) FROM Account WHERE ...];

2) Render them on the screen:

 

<apex:repeat value="{!accounts}" var="account">
  <apex:pageBlock title="{!account.name}">
    <apex:pageBlockTable value="{!account.contacts}" var="contact">
      <apex:column headerValue="Contact Name" value="{!Contact.Name}"/>
    </apex:pageBlockTable>
  </apex:pageBlock>
</apex:repeat>

3) Enjoy the fruits of your (my?) labor!

All Answers

sfdcfoxsfdcfox

A simple task that requires just three easy steps:

 

1) Query the accounts and contacts:

 

... = [SELECT Id,Name,(SELECT Id,Name FROM Contacts) FROM Account WHERE ...];

2) Render them on the screen:

 

<apex:repeat value="{!accounts}" var="account">
  <apex:pageBlock title="{!account.name}">
    <apex:pageBlockTable value="{!account.contacts}" var="contact">
      <apex:column headerValue="Contact Name" value="{!Contact.Name}"/>
    </apex:pageBlockTable>
  </apex:pageBlock>
</apex:repeat>

3) Enjoy the fruits of your (my?) labor!

This was selected as the best answer
veeru417veeru417

Thaks dude