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
sonali  vermasonali verma 

How to show related contacts

Hello friends
 I have a requirement where I need to display under each account name its related contacts & opportunities in a single visual force page.
like as follows:

Accname:AxisBank
contact1:
oppor1:

Kindly let me know.
regards
sonali verma


 
Best Answer chosen by sonali verma
Shrikant BagalShrikant Bagal
Hello sonali,
@amit you can use setController for this purpose.

Please try
--------------------------------------------------------------------------------------------------------------------------

<apex:page standardController="Account" recordSetVar="accounts" tabstyle="account" sidebar="false">
    <apex:pageBlock >
          <apex:repeat value="{!accounts}" var="a">
<apex:pageBlockSection title="{!a.name}"></apex:pageBlockSection>
  <apex:relatedList list="Contacts" subject="{!a.Id}"/>
<apex:relatedList list="Opportunities" subject="{!a.Id}" />
</apex:repeat>      
     </apex:pageBlock>
</apex:page>

--------------------------------------------------------------------------------------------------------------------------------

Please mark as best answer so it will help to other who will serve same problem.
​Thanks! 





All Answers

Amit Chaudhary 8Amit Chaudhary 8
Please try below code
<!-- 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 Visualforce Developer's Guide Quick Start Tutorial for more information. -->


<apex:page standardController="Account">
    <apex:pageBlock>
    You're looking at some related lists for {!account.name}:
    </apex:pageBlock>

    <apex:relatedList list="Opportunities" />

    <apex:relatedList list="Contacts">
        <apex:facet name="header">Titles can be overriden with facets</apex:facet>
    </apex:relatedList>

    <apex:relatedList list="Cases" title="Or you can keep the image, but change the text" />
</apex:page>




http://sfdcsrini.blogspot.com/2014/06/view-all-account-related-contacts-in.html

Please mark  this as solution if this will help you
Shrikant BagalShrikant Bagal
Hello sonali,
@amit you can use setController for this purpose.

Please try
--------------------------------------------------------------------------------------------------------------------------

<apex:page standardController="Account" recordSetVar="accounts" tabstyle="account" sidebar="false">
    <apex:pageBlock >
          <apex:repeat value="{!accounts}" var="a">
<apex:pageBlockSection title="{!a.name}"></apex:pageBlockSection>
  <apex:relatedList list="Contacts" subject="{!a.Id}"/>
<apex:relatedList list="Opportunities" subject="{!a.Id}" />
</apex:repeat>      
     </apex:pageBlock>
</apex:page>

--------------------------------------------------------------------------------------------------------------------------------

Please mark as best answer so it will help to other who will serve same problem.
​Thanks! 





This was selected as the best answer
prasanth kumarprasanth kumar
use this .........

<apex:detail subject="{!'00128000003FuHb'}" relatedlist="true"  />

replace the above number subject value with your record id.  U can use how many as u want. 

example:- 
<apex:detail subject="{!'00128000003FuHb'}" relatedlist="true"  />
<apex:detail subject="{!'008723987003FuHb'}" relatedlist="true"  />
<apex:detail subject="{!'001223723603FuHb'}" relatedlist="true"  />

Note:- standardcontroller="account"      is not mandatory, its u r choice in this program.

please like this post if it useful to u. 
Shrikant BagalShrikant Bagal
Hello prasanth,

your code will display all details page of Account with All related list which will not fit with requirement.

 
prasanth kumarprasanth kumar
shrikant bagal, u r page ouput is awesome.  
Shrikant BagalShrikant Bagal
Thansk! :)
Shrikant BagalShrikant Bagal
Hello Sonali,
Please mark as best answer so it will help to other who will serve same problem.
​Thanks! 
 
sonali  vermasonali verma
Hi Shrikant
The code what you sent fits my requirement. Thanks

regards
sonali verma