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
Shreyashi Akhauri 6Shreyashi Akhauri 6 

write a vf page and controller to dispaly the below table.

Account nameContact NumberOppty Amount
A1123456(C3 recently created)$4000(op2 recent Created)
 
Data: A1
C1 – 1234
C2 – 12345
C3 – 123456
Op1 – 3000
Op2- 4000
 
NagendraNagendra (Salesforce Developers) 
Hi Shreyashi,

Please find the sample code below and tweak it as per the requirement.

Visual Force 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>
Apex 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.

Kindly mark this as solved if the reply was helpful.

Thanks,
Nagendra

 
Shaik Naga janiShaik Naga jani
Hi Shreyashi,

Please find the below sample code below it may useful to you.
Apex Class
public class AccountRelatedDataController {
	Id idAcc;
    public list<AccountWrapper> lstWrapper {get;set;}
    
    public AccountRelatedDataController(ApexPages.StandardController stdController) {   
		idAcc = stdController.getId();    
        getAccountRelatedData();
    }
    
    public void getAccountRelatedData() {
       lstWrapper = new list<AccountWrapper>();
        list<Account> lstAccs = [Select Id, Name, (Select Id, Phone From Contacts ORDER BY CreatedDate DESC LIMIT 1), (SELECT Id, Amount From Opportunities ORDER BY CreatedDate DESC LIMIT 1) FROM Account Where Id=:idAcc];
        for(Account aIterator : lstAccs) {
            AccountWrapper objWrapper = new AccountWrapper();
            objWrapper.objAcc = aIterator;
            for(Contact cIteator : aIterator.Contacts) {
                objWrapper.strPhone = cIteator.Phone;
            }
            for(Opportunity opIterator : aIterator.Opportunities) {
                objWrapper.dAmount = opIterator.Amount;
            }
            lstWrapper.add(objWrapper);
        }
    }
    
    // Wrapper Class
    public class AccountWrapper {
        public Account objAcc {get;set;}
        public String strPhone {get;set;}
        public Decimal dAmount {get;set;}
    }
}

Visualforce Page
<apex:page standardController="Account" extensions="AccountRelatedDataController">
    <apex:form>
    	<apex:pageBlock>
        	<apex:pageBlockSection title="Account Related Information " columns="1" collapsible="false">
            	<apex:pageBlockTable value="{!lstWrapper}" var="data">
                    <apex:column headerValue="Account Name" value="{!data.objAcc.Name}" />
                     <apex:column headerValue="Contact Number" value="{!data.strPhone}" />
                    	<apex:column headerValue="Opportunity Amount" value="{!data.dAmount}" />
                </apex:pageBlockTable>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Kindly mark this as solved if the reply was helpful.
Thanks
Shaik