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
MubarakMubarak 

How to get the child Records

Hi all.
How to get child records of particular record.
I am having one search bar ,if i enter any record and click getChildRecord,it will display the child records of only the particular records.
VFPages...
<apex:page StandardController="Account" extensions="getchildRecords">
  <apex:form >
  <apex:pageBlock title="Child Records of Account">
  Enter Account Name:
  <apex:inputText value="{!SearchString}" /><br></br><br></br>
  <apex:CommandButton value="Get Child Records" action="{!GetChildRecords}"/>
    </apex:pageBlock>
   
  </apex:form>
</apex:page>

Class...
public class getchildRecords {
Public string SearchString {get;set;}
Public List<Account> acc{get;set;}

    public getchildRecords(ApexPages.StandardController controller) {
    

    }
Public void GetchildRecords(){
SearchString=[Select Name,(Select Name,Email from Contacts) from Account limit 2];
acc=Database.Query(SearchString);

}
}

Here I want to get the child records for Account Records.
How to achieve this.


Thanks 
Rahul SharmaRahul Sharma
This doesn't seems to be a good design.

You should have a searchbox for search. on search show all the matching accounts in table below searchbox.
Have a link or button for each account record, on click of which display all the related contact records below Accounts.

Let us know if you face any problems with implementation.
Amit Chaudhary 8Amit Chaudhary 8
If you want to display account related contact then please try below code
 
<apex:page standardController="Account">
   <apex:pageBlock title="Hello {!$User.FirstName}!">
      You are viewing the {!account.name} account.
   </apex:pageBlock>
   <apex:pageBlock title="Contacts">
      <apex:pageBlockTable value="{!account.Contacts}" var="contact">
         <apex:column value="{!contact.Name}"/>
         <apex:column value="{!contact.MailingCity}"/>
         <apex:column value="{!contact.Phone}"/>
      </apex:pageBlockTable>
   </apex:pageBlock>
</apex:page>

If you want to do custom search then please try below blog code :-

http://amitsalesforce.blogspot.in/search/label/Pagination

Please let us know if this will help you.
 
Amit Chaudhary 8Amit Chaudhary 8
Please let us know if above solution helps u
MubarakMubarak
Amit 
Thanks for ur reply.
Its not working.But i tried with some other way and  now its working.