Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
Hi Guys,
I have scenario like this, I have to display all the contacts related Accounts in visual force page.
How to write th Apex class for this.
Thanks,
Shaik
I wrote a blog post on this topic (although it allowed editing of the contact data too) - see if that gets you started:
http://bobbuzzard.blogspot.co.uk/2011/04/edit-parent-and-child-records-with.html
I want in this format.
First NameLast NamePhoneEmail
Configure Map<Account, List<Contact>> in the controller, that will contain Account as key and related Contacts as value.
Then on the page add something like this:
<apex:page> . . . <apex:repeat value="{!yourMap}" var="account"> <apex:pageBlockSection title="account.Name"> <apex:pageBlockTable value="{!yourMap[account]}" var="contact"> . . . <!-- Add columns which you need --> . . . </apex:pageBlockTable> </apex:pageBlockSection> </apex:repeat> . . . </apex:page>
Hi,
Please send me the query using map.I am getting error.
Bujji
Try this:
Map<Account, List<Contact>> accountToContacts = new Map<Account, List<Contact>>(); List<Account> accounts = [ SELECT Name, (SELECT FirstName, LastName, Phone, Email FROM Contacts LIMIT 2000) FROM Account LIMIT 50000]; for(Account acc : accounts) { if(acc.Contacts != NULL && (!acc.Contacts.isEmpty())) { accountToContacts.put(acc, acc.Contacts); } }
The query is not getting any values i checked in debug console.
I am sending code please check this.
In the related list i am printing account. But i want contacts related to page block section accounts in related list.
<apex:page standardController="Account" extensions="ExtensionPage" showHeader="false"><apex:pageBlock id="pb" title="Accountd With Contacts"> <apex:repeat value="{!records}" var="r" > <apex:pageBlockSection title="{!r.Name}" collapsible="false" /> <apex:pageBlockTable value="{!r}" var="contact"> <apex:column headerValue="Account Name" >{!contact.Name}</apex:column> <apex:column headerValue="Phone" >{!contact.phone}</apex:column> <apex:column headerValue="Billing State/Province" >{!contact.BillingState}</apex:column> <apex:column headerValue="Website" >{!contact.Website}</apex:column> </apex:pageBlockTable> </apex:repeat></apex:pageBlock></apex:page>
*******************************************************************************************************
public class ExtensionPage { public ExtensionPage(ApexPages.StandardController controller) { } public List<Account> getRecords(){ List<Account> accs = [Select Id,Name,phone,BillingState,Website From Account Limit 5]; return accs; } }
I wrote a blog post on this topic (although it allowed editing of the contact data too) - see if that gets you started:
http://bobbuzzard.blogspot.co.uk/2011/04/edit-parent-and-child-records-with.html
I want in this format.
Express Logistics and TransportFirst NameLast NamePhoneEmail
Configure Map<Account, List<Contact>> in the controller, that will contain Account as key and related Contacts as value.
Then on the page add something like this:
Hi,
Please send me the query using map.I am getting error.
Thanks,
Bujji
Try this:
Hi,
The query is not getting any values i checked in debug console.
I am sending code please check this.
In the related list i am printing account. But i want contacts related to page block section accounts in related list.
<apex:page standardController="Account" extensions="ExtensionPage" showHeader="false">
<apex:pageBlock id="pb" title="Accountd With Contacts">
<apex:repeat value="{!records}" var="r" >
<apex:pageBlockSection title="{!r.Name}" collapsible="false" />
<apex:pageBlockTable value="{!r}" var="contact">
<apex:column headerValue="Account Name" >{!contact.Name}</apex:column>
<apex:column headerValue="Phone" >{!contact.phone}</apex:column>
<apex:column headerValue="Billing State/Province" >{!contact.BillingState}</apex:column>
<apex:column headerValue="Website" >{!contact.Website}</apex:column>
</apex:pageBlockTable>
</apex:repeat>
</apex:pageBlock>
</apex:page>
*******************************************************************************************************
public class ExtensionPage {
public ExtensionPage(ApexPages.StandardController controller) {
}
public List<Account> getRecords(){
List<Account> accs = [Select Id,Name,phone,BillingState,Website From Account Limit 5];
return accs;
}
}
Thanks,
Shaik