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 related child record on click of specific parent record on vf page


Can anybody please help me in below query,

My requirment is, There are two objects Goal and related Actions. 
So On vf page I am displaying all goals and all Actions records but I want to give Link to Goal record and onClick of this fetch only related Action records and not all records. How to achieve this on VF?

Gaurish Gopal GoelGaurish Gopal Goel
Hi Tejashree, follow these steps to achieve this requirement:
1. Call a method on the Link of Goal Record. Send Goal record ID as the parameter.
2. Now write a query in your method and return the list of Action records related to that ID only. Make your list public.
3. Display that list on VF page.

Please do not forget to mark this thread as SOLVED and answer as the BEST ANSWER if it helps address your issue.
Hi @Gaurish Gopal Goel  
Thanks for reply. Below is my code can you please suggest what exactly I need to do here ?
<apex:page standardController="Care_Plan__c" extensions="CarePlanController">
   <apex:form >
     <apex:pageBlock >
            <apex:pageBlockSection >
                <b>Client:</b> {!care.Contact__c} <br/>
                <!-- Display Goals Data -->
             <apex:pageBlockSection >    
                  <apex:pageBlockTable value="{!goalsRecords}" var="g">
                      <apex:column >
                          <apex:facet name="header">Goal</apex:facet>
        <!-- Display action step data -->   
       <apex:pageBlock id="actionStepId" >
                    <apex:pageBlockSection > <!-- rendered="{!showActionRec}">  -->
                        <apex:pageBlockTable value="{!actionStepRec}" var="a">
                            <apex:column value="{!a.Action_Number__c}"/>

Controller - 
public with sharing class CarePlanController {
    public Care_Plan__c care {get; set;}
    public List<Goal__c> allGoalsRec {get; set;}
    public List<Goal__c> goalsRecords {get; set;}
    public List<Action_Step__c> allActionStepRec {get; set;}
    public List<Action_Step__c> actionStepRec {get; set;}  
   // public boolean showActionRec{get;set;}
         public CarePlanController(ApexPages.StandardController controller) {
            String careid = ApexPages.currentPage().getParameters().get('id');
           // showActionRec = false;
            care = [SELECT Id, Name,Contact__c,Completion_Date__c FROM Care_Plan__c where id=: careid];
            //Goals data in list
            allGoalsRec = [select id,name,Goal_Number__c from Goal__c where Care_Plan__c =: careid];
            goalsRecords = new List<Goal__c>(allGoalsRec);   
            //related action step data in list
            allActionStepRec = [select id,name,Action_Number__c from Action_Step__c where Goal__c =: goalsRecords];
            actionStepRec = new List<Action_Step__c>(allActionStepRec); 
         public List<Goal__c> getGoals(){
          return goalsRecords;
        public List<Action_Step__c> getActionStep(){
        //showActionRec = true;
       return actionStepRec;