+ Start a Discussion
Ishan K SharmaIshan K Sharma 

Show records from multiple objects in one table


I have 4 objects in relation.Let's say obj1,obj2,obj3,obj4.Obj2 and obj3 both have lookup to obj1 or say obj1 is parent of both.And Obj4 is child of obj3. Now i want to create dynamic tables on basis of no. of records in Obj1 whose rows will come from obj2 and obj4's records. No. of tables in my vf page wil be no. of records user inserted in obj1 . Rows of every table will be no.of records in obj2 plus records of obj4 related to obj1 respectively. Table has 2 colums which is the fields of obl2 and obj4.


Now problem is obj4 is not direct child of obj1 and i cannot do subquerry into a subquerry. How should i approch this?



According to what you wrote obj4 is child of obj3, and obj3 have lookup to obj1,

so you should be able to query obj4 by:


select id, name
from obj4
where obj3reference.obj1reference = :idObj1

Ayub HeartForceAyub HeartForce

Hi Ishan,


You can use following query to select all record in single list.


List<Object1>  listObject1 = [select name ,(select name from object2 where object1refernce IN :  object1Ids), (Select name from Object 4 where obj3referencefromObject4.obj1referencefromObject2 IN :object1Ids)];


If this post helps you than please mark it as a solution and don't forget to give me kudo's.