You need to sign in to do that
Don't have an account?
Rabbani sayyed 8
I want to create a VF page that display list of accouts and when i select a particular account i want related contact to be displayed there itself. i dont want page to redirect to another page? Can anyone share me the VF code for this?
I want to create a VF page that display list of accouts and when i select a particular account i want related contact to be displayed there itself. i dont want page to redirect to another page? Can anyone share me the VF code for this?
Have you achieved the first part .Display list of account ?
Below is the complete vf page and controller attached. Click on the "Click" link in the Account records to display contact below.
<!--------- VF PAGE -------------->
<apex:page id="pgId" controller="AccountDetails">
<Apex:form>
<apex:pageBlock>
<Apex:pageblockSection title="Accounts">
<apex:pageBlockTable value="{!accounts}" var="account">
<Apex:column headervalue="Account id">
<Apex:outputPanel >
<Apex:outputText value="Click" />
<apex:actionSupport event="onclick" action="{!getContactDetails}" rerender="contactBlock" >
<Apex:param name="accountId" assignTo="{!accountId}" value="{!account.Id}"/>
</apex:actionSupport>
</apex:outputPanel >
</apex:column>
<Apex:column headervalue="Account name">
<Apex:outputField value="{!account.Name}" />
</apex:column>
</apex:pageBlockTable>
</Apex:pageblockSection>
</apex:pageBlock>
<apex:pageBlock id="contactBlock">
<Apex:pageblockSection title="Contacts">
<apex:pageBlockTable value="{!contacts}" var="contact">
<Apex:column headervalue="Contact id">
<Apex:outputField value="{!contact.Id}"/>
</apex:column>
<Apex:column headervalue="Contact name">
<Apex:outputField value="{!contact.Name}" />
</apex:column>
</apex:pageBlockTable>
</Apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
<!---Controller --->
public with sharing class AccountDetails{
public list<Account> accounts{get;set;}
public String accountId{get;set;}
public list<contact> contacts{get;set;}
public AccountDetails(){
accounts = [select Id,Name from Account limit 10];
}
public void getContactDetails(){
contacts = [select Id,Name from Contact where AccountId =:accountId];
}
}
I hope it solves your problem, feel free to ask if there is any issue.
Thanks
Nitin
I am trying with the code that you have shared but it's giving me the error. please find the below error.
Error: AccountDetails Compile Error: Illegal assignment from List<Account> to List<Account> at line 6 column 1
Regards
Rabbani
Yes i tried
Regards
Rabbani
Please check do you have an apex class named as"Account" in your org?
Thanks
Nitin
Hi,
Its working fine in my environment, and the only issue which i can think of if that there must be an apex class named as "Account".
Check this link
https://developer.salesforce.com/forums?id=906F00000008vO5IAI
Thanks
Nitin
Try below codean dlet us know any issue .
You can display one msg if account what you have clicked may be related contacts are not there.
Thnaks
Manoj