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
Dvisha TDvisha T 

Visualforce page to display account,contact and its related opportunities


Thanks in advance for your help here.
I have a requirement where when i have list of accounts clicking on it it should display account,contacts and related opportunities in a single visual page of a particular account clicked.
Pls note it should not go to any detaul page.
JyothsnaJyothsna (Salesforce Developers) 
Hi Dvisha,

Please check the below sample code.

VisualForce Page:
<apex:page controller="AccContact">
  <apex:form >
  <apex:pageBlock >
  <apex:pageBlockTable value="{!acclst}" var="a">
 <apex:column headerValue="Name">
  <apex:commandLink action="{!selacc}">
  <apex:param name="conlst" value="{!}"/>
  <apex:outputText value="{!}"/>
    <apex:pageBlockTable value="{!accconts1}" var="a">
    <apex:column headerValue="AccountName" value="{!a.Name}"/>
    <apex:column headerValue="list contacts">
   <apex:pageBlockTable value="{!a.contacts}" var="c">
  <apex:column headerValue="ContactName">
  <apex:outputText value="{!c.lastname}"></apex:outputText>
  <apex:column headerValue="Opportunity list">
  <apex:pageBlockTable value="{!a.opportunities}" var="p">
  <apex:column headerValue="Opportunity Name">
  <apex:outputText value="{!}">
  </apex:pageBlockTable><!-- End opportunity-->
 </apex:pageBlockTable><!-- End contact-->
 </apex:pageBlockTable><!--end account-->

public with sharing class AccContact {

    public list<contact> conlst { get; set; }

   // public contact c { get; set; }
   /* public  void getSelacc() {

    public list<account> accconts1 { get; set; }

    public PageReference selacc() {
    string getid=apexpages.currentpage().getparameters().get('conlst');
         accconts1=[select id,name,(select id,lastname from contacts) ,(select name from Opportunities ) from account where id=:getid ];
      return null;

    public List<Account> acclst { get; set; }
   public  AccContact (){
     acclst=[select id,name  from account ];

Please copy the above code and paste your account.

Please mark it as best answer if it really helpful.
Best regards,
Dvisha TDvisha T
Hi Jyothsna,

Thank you for your help here,but i still see the Account name list still visible in the visualforce page.
Let me know why am seeing in vf page
Once i click the specific account i should only see the account,contact and opp in that page.

Heather Myers 8Heather Myers 8
I would be very thankful if you continue with quality what you are college application essay writing service ( serving right now with your blog...I really enjoyed it...and i really appreciate to you for this....its always pleasure to read so....Thanks for sharing!!!
renaiah anamalla 7renaiah anamalla 7
<apex:page standrardcontroller="Account">
<apex:pageblocktable value="{!results}" var="a">
<apex:column value="{!a.Name}"/>
<apex:column value="{!}"/>

try this
hannah rosshannah ross
Many thanks for the timely help, I had a similar issue at assignmetn hub ( I literally looked up eveywhere for th solution finally found here.
harish vinjamuriharish vinjamuri
Can i get a lookup at the top of the page which shows the account details?
Shelly NyeinShelly Nyein
Hi, I have the code as per below to get fields from contacts, opportunities and Accounts. I do not want to use List because my visual force page is to display only one account and its related contact fields. I can only get Contact fields and Account fields. Can anyone suggest me how to get Opportunities fields?

<apex:page showHeader="false" standardStylesheets="false" standardController="Contact">
<apex:variable value="{!Contact}" var="c" />
                 <p> <apex:outputField value="{!c.Account.Name}"/><br />
                 <apex:outputField value="{!c.MailingStreet}"/><br /> </p>