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
Varun TejaVarun Teja 

We have 3 objects Account, Contact, Opportunity. In a VF page using controller we need to display the contact & Opportunity details which are related to Account.

We have 3 objects Account, Contact, Opportunity. In a VF page (using controller) we need to display the contact & Opportunity which are related to Account.Here the condition is, For paticular Account 'Show Contacts' and 'Show Opportunity' and 'Reset' buttons are there.
1. If 'show contacts' button click it will fetch the particular account contacts only display in tabular , but here 'Show Contacts'  button should be disable and   'Show Opportunity' button will be enable.
2. If 'show Opportunity' button click it will fetch the particular account contacts only display in tabular , but here 'Show Opportunity'  button should be disable and   'Show Contacts' button will be enable.

Ex: TestAccount1      'Show Contacts'    'Show Opportunity'    'Reset'
       TestAccount2     'Show Contacts'    'Show Opportunity'    'Reset'
       TestAccount3     'Show Contacts'    'Show Opportunity'    'Reset'

Could you please help on this
NagendraNagendra (Salesforce Developers) 
Hi Nagarjuna,

Try the below visualforce page code using standard controller to display the Account information and its related Contact and Opportunity records
<apex:page standardController="Account">
  Name : <apex:outputField value="{!Account.Name}"/> <br/>
  Phone : <apex:OutputField value="{!Account.Phone}" /><br/>
  <br/>
  <b>Contact List</b><br/>
  <apex:dataTable value="{!Account.Contacts}" var="con">
      <apex:column value="{!con.Name}"/>
  </apex:dataTable><br/><br/>
  <b>Opportunity List</b><br/>  
  <apex:dataTable value="{!Account.Opportunities}" var="opty">
      <apex:column value="{!opty.Name}"/>
  </apex:dataTable>
</apex:page>
In another way, you can do this using standardController "Account" and in extension use the below query and replace XXXX's with dynamic account Id using(GetRecord Method of the controller).
List<Contact> contacts=[Select Id, Name From Contact where AccountId='XXXXXXXXXXXXXXX'];

List<Opportunity> opps=[Select Id, Name From Opportunity where AccountId=''XXXXXXXXXXXXXXX'];
Hope this helps.

Kindly mark this as solved if the reply was helpful.

Thanks,
Nagendra