I have three objects

Object A - Parent Object B - Child ( Lookup to A) Object C - Child (Lookup to A)

B and C are not related directly, I have to fetch the fields from object C where my query is written on Object B.

Now, I have already a query written on Object B through which I am fetching some fields from Object A but not sure how can I modify it to fetch the fields from Object C or I have to write a separate query altogether to fetch the fields from C.

1 Answer 1


Relationships between the object are as below

  • ObjectB - No Parent
  • ObjectA - Parent ObjectB
  • ObjectC - Parent OjbectA

As per salesforce soql limitations.

In each specified relationship, only one level of parent-to-child relationship can be specified in a query.

Hence you have to use two different queries to get ObjectC records, if you want to keep existing query on objectB. Total 2 queries will be required to get data from all 3 objects.

Workaround for single query:

While taversing from child to parent you can go 5 levels up. By using middle object ObjectA you can get all 3 object fields.


    Id, Name, ..........,
    ObjectB.Id,  ObjectB.Name ........,
            Id, Name,.....
FROM ObjectA
  • Thanks, I was sensing the same that I have to go through the separate query route. Appreciate your quick response.
    – Priya
    May 11, 2022 at 6:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .