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
sagarrrrsagarrrr 

1. Query and display all the accounts in a tabular format on a visualforce page. 2. Display the columns name, phone, address. 3. The name should be a hyperlink and on click of the link display contact

1. Query and display all the accounts in a tabular format on a visualforce page.
2. Display the columns name, phone, address.
3. The name should be a hyperlink and on click of the link display contacts and opportunity records
related to the account in different page block tables.
4. The page should be partially rendered and it should not reload. 

plz help me i am new for vf page
Best Answer chosen by sagarrrr
Khan AnasKhan Anas (Salesforce Developers) 
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:
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];
    }
}

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.

Thanks and Regards,
Khan Anas