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
Anil Bolisetty 2Anil Bolisetty 2 

Request to retrieve child record from parent record of the same custom object


I have a custom object where an record can have child and in turn child can have one more child ,could any one help me with the logic to retrieve all the child records give the id of the parent record
Hi Anil,

The parent and child relations are they of the same record type?
  1. If they are of same object type looking up to each other in the relationship or different objects 
    • Assuming you only have two levels i.e. parent->child->child, you can have two formula fields which gives the record id of the parent id's at both levels and use it to query from the child with and or condition where either one of the child records have formula value as the parent record
  2. If the relation is like a tree i.e. Parent 1 -> Child 1 -> Child2-> Child 3, here the Child one is like the parent of the Child 2 and the Child 2 is the parent of the Child3, here the the relation would keep on growing. Here what you can do is when a parent is selected, make sure that a field is updated with a uniques identifier for that Child, and use the field in the query to fetch all the child records.
Hope it helps