Hi Sagar,Greetings to you!Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.Visualforce: <apex:page controller="AccountConOppC" sidebar="false">
<apex:form >
<apex:pageBlock title="AccountTable">
<apex:pageBlockTable value="{!Acclst}" var="A">
<apex:column headerValue="NAME OF THE ACCOUNT" >
<apex:commandLink value="{!A.Name}" action="{!showDetails}" rerender="conttable,opptable">
<apex:param value="{!A.Id}" name="idForConts" assignTo="{!recid}"/>
</apex:commandLink>
</apex:column>
<apex:column value="{!A.Phone}"/>
<apex:column value="{!A.BillingStreet}"/>
<apex:column value="{!A.BillingCity}"/>
<apex:column value="{!A.BillingState}"/>
<apex:column value="{!A.BillingPostalCode}"/>
<apex:column value="{!A.BillingCountry}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
<apex:pageBlock title="Contacts">
<apex:pageBlockTable value="{!contacts}" var="con" id="conttable">
<apex:column value="{!con.FirstName}"/>
<apex:column value="{!con.LastName}"/>
<apex:column value="{!con.Email}"/>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageBlock title="Opportunities">
<apex:pageBlockTable value="{!opportunities}" var="opp" id="opptable">
<apex:column value="{!opp.Name}"/>
<apex:column value="{!opp.StageName}"/>
<apex:column value="{!opp.CloseDate}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
Controller:
I hope it helps you.Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.public class AccountConOppC {
public string recid{get;set;}
public list<Account> Acclst{get;set;}
public List<Contact> contacts {get; set;}
public List<Opportunity> opportunities {get; set;}
public AccountConOppC(){
Acclst = [SELECT Id, Name, Phone, BillingCountry, BillingPostalCode, BillingState, BillingCity, BillingStreet FROM Account LIMIT 10];
contacts=null;
opportunities=null;
}
public void showDetails() {
contacts=[SELECT Id, FirstName, LastName, Email FROM Contact WHERE AccountId=:recId];
opportunities=[SELECT Id, Name, StageName, CloseDate FROM Opportunity WHERE AccountId=:recId];
}
}
Thanks and Regards,
Khan Anas
1 answer