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
Ashritha ReddyAshritha Reddy 

hii devs

how can we display the opportunites account related list along with oppetunity name can any one answer this question please?
Best Answer chosen by Ashritha Reddy
JyothsnaJyothsna (Salesforce Developers) 
Hi Ashritha,

Please check the below code.The below code display Account related contact and opportunities when you select a particular account name. Based on your requirement you can change the query.

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);
   
   }
}

Hope this helps you!

 Please mark it as Best Answer if my answer was helpful. It will make it available for other as the proper solution. 

Best Regards,
Jyothsna

All Answers

PRIYAN NEERUDUPRIYAN NEERUDU
<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>


---------------------
thanks,
Priyanka.N
JyothsnaJyothsna (Salesforce Developers) 
Hi Ashritha,

Please check the below code.The below code display Account related contact and opportunities when you select a particular account name. Based on your requirement you can change the query.

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);
   
   }
}

Hope this helps you!

 Please mark it as Best Answer if my answer was helpful. It will make it available for other as the proper solution. 

Best Regards,
Jyothsna
This was selected as the best answer