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

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.
<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}"/>

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];


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

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.
   <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}"/>

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

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