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

Hi,

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="{!a.id}"/>
  <apex:outputText value="{!a.name}"/>
  </apex:commandlink>
  </apex:column>
  <!--accounts-->
   </apex:pageBlockTable>
    <apex:pageBlockTable value="{!accconts1}" var="a">
    <apex:column headerValue="AccountName" value="{!a.Name}"/>
    <!--contacts-->
    <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>
  <!--opportunities-->
  <apex:column headerValue="Opportunity list">
  <apex:pageBlockTable value="{!a.opportunities}" var="p">
  <apex:column headerValue="Opportunity Name">
  <apex:outputText value="{!p.name}">
  </apex:outputText>
  </apex:column>
  </apex:pageBlockTable><!-- End opportunity-->
  </apex:column>
 </apex:pageBlockTable><!-- End contact-->
 </apex:column>
 </apex:pageBlockTable><!--end account-->
  </apex:pageBlock>
  </apex:form>
</apex:page>


Controller:
 
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 ];
            system.debug(accconts1);
      return null;
    }


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

Please copy the above code and paste your account.

Please mark it as best answer if it really helpful.
Best regards,
Jyothsna
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 (http://www.admission-service.com/) 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:form>
<apex:pageblock>
<apex:pageblocktable value="{!results}" var="a">
<apex:column value="{!a.Name}"/>
<apex:column value="{!a.contact.Firstname}"/>
</apex:pageblocktable>
</apex:pageblock>
</apex:form>
</apex:page>

try this
hannah rosshannah ross
Many thanks for the timely help, I had a similar issue at assignmetn hub (http://assignmenthub.co.uk/) 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>
</apex:page>