You need to sign in to do that
Don't have an account?

Group Records in PageBlockTable
Hi,
I am looking for possible solution to get this result:
Account Name Contact Name
United Oil & Gas Corp. Lauren Boyle
United Oil & Gas Corp. Avi Green
sForce Jake Llorrac
University of Arizona Jane Grey
University of Arizona Arthur Song
Though, I am getting this result with my regular code:
Account Name Contact Name
United Oil & Gas Corp. Lauren Boyle
Avi Green
sForce Jake Llorrac
University of Arizona Jane Grey
Arthur Song
Now, here is my code on Visualforce Page:
<apex:pageblocksection id="pbsAccnt" rendered="true"> <apex:pageBlockTable id="pbtAccnt" value="{!lstACcount}" var="AC"> <apex:column headerValue="Account(s)" value="{!AC.Accnt__c}" /> <apex:column headerValue="Contact(s)" value="{!AC.Cont__c}" /> </apex:pageBlockTable> </apex:pageblocksection>
I already tried with Wrapper class with <apex:repeat> but it is not working.
Any help would be greatly appreciated.
Hi,
This blog from Bob Buzzard will help you to display Account and Its Contact records.
Thanks,
Devendra
All Answers
You can retrieve Contact records by keeping ORDER BY on Account Name.
List<Contact> lstContact = [Select Id, AccountId, Account.Name, LastName from Contact Order BY Account.Name];
and display this list in PageBlockTable.
Thanks,
Devendra
Thanks Devendra... That worked. ORDER BY was totally skipped from my mind.
Hi,
I am getting result with helping your query, but I am still getting Account name repeated. So, is there any way to display just Account name in single line with all related records?? It can be different columns but no repeating account name.
Hi,
This blog from Bob Buzzard will help you to display Account and Its Contact records.
Thanks,
Devendra
Thanks Devendra.
I think you could use this idea for gouping records by a particular field in a table.
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000kGikIAE
This is the result of grouping contacts by account.
