+ Start a Discussion
gopal m 14gopal m 14 

please help me

1. We have 3 objects Account, Contact, Opportunity.

   In a VF page, we need to display the names of contact & Opportunity which are related to Account.
Best Answer chosen by gopal m 14
rashi krishanrashi krishan
 To display the names of contact & Opportunity which are related to Account we do the follwing in the vf page
<apex:page standardController = ''Account''>
<apex:pageBlock>
<apex:pageBlockTable value ="{!Account.Contacts}"  var=con  title="Contact name">
<apex:column value ="{!con.Name}"/>
<apex:pageBlockTable value ="{!Account.Opportunity}"  var=opp  title="Contact name">
<apex:column value ="{!opp.Name}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>

All Answers

sharathchandra thukkanisharathchandra thukkani
It depends on how you want to see the records.

In the account detail page you can see contact and opportunity details in those respective related lists.

If you want some thing linke list of account and on click/on hover  of account you need to show contact and opportunity details you need to go with VF page.

Please refer to visual force developer guide.
 
Vishal Negandhi 16Vishal Negandhi 16
How does the VF work?
Will the user be selecting an Account record, based on which you want to display the related Contacts and Opportunities?

On a standard Account detail page, you already has this information available in the related lists. 
So what's the purpose of having this page and showing the same data?
KaranrajKaranraj
Gopal - You can use apex:relatedlist vf tag to display the realted record information in your visualforce page or you can use apex:pageblockTable to display the related record informations

Check the below sample code which demonstrates for both relatedlist example and Pageblocktable example.
<!-- For this example to render properly, you must associate the Visualforce page
with a valid account record in the URL.
For example, if 001D000000IRt53 is the account ID, the resulting URL should be:
https://Salesforce_instance/apex/myPage?id=001D000000IRt53
See the Trailhead Visualforce basic Tutorial for more information.
https://developer.salesforce.com/trailhead/module/visualforce_fundamentals
 -->


<apex:page standardController="Account">
    <apex:pageBlock >
    
    Youre looking at some related lists for {!account.name}:
    </apex:pageBlock>
    <!-- Example using Related List -->
    <apex:relatedList list="Opportunities" />
    <apex:relatedList list="Contacts" />
    <!-- Example using page block table -->
    <apex:pageBlock title="Example with Page block table">
    Contact Record Example
     <apex:pageBlockTable value="{!Account.contacts}" var="con" title="Contact records">
       <apex:column value="{!con.Name}"/>
     </apex:pageBlockTable>
     Opportunity Record Example
     <apex:pageBlockTable value="{!Account.Opportunities}" var="opty" title="Opportunity records">
       <apex:column value="{!opty.Name}"/>
     </apex:pageBlockTable>
    </apex:pageBlock>    
   
</apex:page>

Trailhead module - https://developer.salesforce.com/trailhead/module/visualforce_fundamentals
rashi krishanrashi krishan
 To display the names of contact & Opportunity which are related to Account we do the follwing in the vf page
<apex:page standardController = ''Account''>
<apex:pageBlock>
<apex:pageBlockTable value ="{!Account.Contacts}"  var=con  title="Contact name">
<apex:column value ="{!con.Name}"/>
<apex:pageBlockTable value ="{!Account.Opportunity}"  var=opp  title="Contact name">
<apex:column value ="{!opp.Name}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
This was selected as the best answer