+ Start a Discussion
Anoop Kumar 31Anoop Kumar 31 

I want to create a visual force page where I have account name and industry with one Button ="Save". If I click on Save button after selecting Account name and Industry then it should show all related contacts to that account.

<apex:page standardController="Account" >
    <apex:form >
        <apex:pageBlock title="Show Attached Contacts">
            <apex:pageBlockSection title="Files" >
             <apex:inputField  value="{!Account.Name}" /> 
              <apex:inputField value="{!Account.Industry}"/> </apex:pageBlockSection>
                             
                <apex:pageBlockButtons location="Bottom">
                    <apex:commandButton value="Click Me!"  />           
                </apex:pageBlockButtons>
            </apex:pageBlock>
    </apex:form>
</apex:page>
Akshay_DhimanAkshay_Dhiman
Hi Anoop,

    Here is a solution to your Problem.
    
    ----VF_Page----------
<apex:page Controller="AccountRelatedContactController">
    <apex:form >
        <apex:pageBlock id="theBlock">
            <apex:sectionHeader title="Account Details"/>
                <apex:pageBlockSection >
                    <apex:pageBlockTable value="{!lstAcc }" var="acc" rows="10">
                       <apex:column headerValue="Account Name" >
                            <apex:commandLink value=" {!acc.Name}" action="{!conDetail}"  reRender="contactlist">  
                                <apex:param name="accId" value="{!acc.id}"/>       
                            </apex:commandLink>
                        </apex:column> 
                        <apex:column headerValue="Industry" value="{!acc.Name}" />
                </apex:pageBlockTable>
                </apex:pageBlockSection>
            </apex:pageBlock>
            <apex:pageBlock >
                <apex:sectionHeader title="Contact Details" />
                <apex:pageBlockSection id="contactlist">
                    <apex:pageBlockTable value="{!lstContact}" var="con">
                      <apex:column value="{!con.Name}" />
                      <apex:column value="{!con.AccountId}" />
                    </apex:pageBlockTable>
                </apex:pageBlockSection>
            </apex:pageBlock>
    </apex:form>
</apex:page>



    -------VF_Controller--------
public with sharing Class AccountRelatedContactController{
    public List<Account> lstAcc{get;set;}
    public List<Contact> lstContact{get;set;}
   
    public AccountRelatedContactController(){
        lstAcc = new List<Account>();
        lstContact = new List<Contact>();
        lstAcc = [Select Id,Name,Industry From Account Where Industry!=null Limit 10];
    }
    
    public PageReference conDetail(){
        String accountId = System.currentPageReference().getParameters().get('accId');
        lstContact = [Select Id,Name,AccountId From Contact Where AccountId =:accountId];
        
        return null;
    }
}



I hope it will help you.
Please select this as Best Answer so that other's also get help from this.
 
Thanks,
Akshay