[SalesForce] Visualforce page with search on account Name and display with child records as a hierarchical view

I have 3 objects like Account, Custom_object__1 and custom Object2__c. Both the custom objects has a master detail relationship with Account. I would like to build a custom visualforce search page where I can search by Account Name and all the child records will be shown in the tables below with editable option.

Any references for this approach is really appreciated.

Best Answer

Try using the following controller and vf page Controller:

public class democlass {
 public string searchboxstring{get; set;}
 public list<contact> result {get; set;}

 public democlass()
 {
  result = new list<Contact>();
 }
 public void searchbox(){
  result=new List<Contact>();
  result=[select ID,Name, account.name from Contact where account.Name =:searchboxstring];
 }
}

Vf Page:

<apex:page controller="democlass">  
<apex:form >
<apex:pageBlock >

 <apex:pageBlockSection columns="2">
 <apex:inputText value="{!searchBoxstring}" label="Search"/>
   <apex:commandButton value="Search" action="{!searchbox}" >

  </apex:commandButton>

    <apex:pageblockTable value="{!result}" var="wl">
     <apex:column value="{!wl.name}"/>
      <apex:column value="{!wl.account.name}"/>
      <apex:column value="{!wl.id}"/>
    </apex:pageblockTable>   
  </apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page> 

This will display contacts of searched account on the page. Let me know if this helps.