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
Teran@18Teran@18 

I need a step by step process of creating visualforce page

Requirement :
Account : 
if i give account name, i should get details of that accounts contact .
contact name,username,email,status.
Khan AnasKhan Anas (Salesforce Developers) 

Hi,

Greetings to you!

Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.

Visualforce:
<apex:page controller="AccContWithUserNameC" 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="{!setupContacts}" rerender="conttable">
                        <apex:param value="{!A.Id}" name="idForConts" assignTo="{!recid}"/>
                    </apex:commandLink>
                </apex:column>  
                <apex:column value="{!A.Id}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
    <apex:pageBlock title="Contacts">
        <apex:pageBlockTable value="{!contacts}" var="contact" id="conttable">
            <apex:column headerValue="First Name" value="{!contact.ct.FirstName}"/>
            <apex:column headerValue="Last Name" value="{!contact.ct.LastName}"/>
            <apex:column headerValue="Email" value="{!contact.ct.Email}"/>
            <apex:column headerValue="UserName" value="{!contact.userName}" />
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

Controller:
public class AccContWithUserNameC {
    
    public string recid{get;set;}    
    public list<Account> Acclst{get;set;}
    public List<ContactWrapper> contacts {get;set;}
    
    public AccContWithUserNameC(){
        contacts = new List<ContactWrapper>(); 
        Acclst = [SELECT Id, Name FROM Account LIMIT 10];
    }
    
    public void setupContacts() {
        for(Contact c : [SELECT id, FirstName, LastName, Email, createdBy.Name FROM Contact WHERE AccountId=:recId]){
            contacts.add(new ContactWrapper (c.CreatedBy.name, c));
        }
    }
    
    public class ContactWrapper{ 
        public String userName {get; set;}
        public Contact ct {get; set;}
        
        public ContactWrapper(String userName, Contact ct) {
            this.userName = userName;
            this.ct = ct;
        }
    }
}

If you don't want UserName then you can use below code.​

Visualforce:
<apex:page controller="AccountContactC" 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="{!setupContacts}" rerender="conttable">
                        <apex:param value="{!A.Id}" name="idForConts" assignTo="{!recid}"/>
                    </apex:commandLink>
                </apex:column>  
                <apex:column value="{!A.Id}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
    <apex:pageBlock title="Contacts">
        <apex:pageBlockTable value="{!contacts}" var="contact" id="conttable">
            <apex:column value="{!contact.FirstName}"/>
            <apex:column value="{!contact.LastName}"/>
            <apex:column value="{!contact.Email}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

Controller:
public class AccountContactC {
    
    public string recid{get;set;}    
    public list<Account> Acclst{get;set;}
    public List<Contact> contacts {get; set;}
    
    public AccountContactC(){
        Acclst = [SELECT Id, Name FROM Account LIMIT 10];
        contacts=null;
    }
    
    public void setupContacts() {
        contacts=[SELECT id, FirstName, LastName, Email FROM Contact 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.

Thanks and Regards,
Khan Anas​​