0

I have 6 objects. All have lookup relation between them Object A has lookup to object B which inturn has lookup to object C. [A-->B -->C ] Object C has lookup to Object D and object E. C --> D C --> E

I need to access field data from object A to E.Name.

I have query like select A__r.B__r.C__r.E__r.Name from object A

The child to parent should work upto 5 levels deep. However This is not working. Could you please help?

5
  • Hey! What error are you getting? Have you checked relationship name properly? Jul 15, 2019 at 14:26
  • What does "not working" mean? are you getting an error, or just a blank value? Also, which objects are the child objects here? Put another way, for your lookup between A and B, is the lookup field itself on object A, or is it on object B? The object that contains the actual lookup field is the child object in the relationship.
    – Derek F
    Jul 15, 2019 at 14:39
  • I think your query should be something like this, Since you have a lookup to object B on A, you probably will start the relationship query from ObjB and downwards. Select ObjAName, ObjB_r.ObjC_r.ObjD_r.ObjE_r.Name FROM ObjA
    – Raj
    Jul 15, 2019 at 14:40
  • @Raj - you should post this as the answer
    – cropredy
    Jul 15, 2019 at 14:43
  • I was getting [Object, Object] when i queried from console. I tried to run from execute anonymous and log the value using system.debug and it worked! I think thats how console behaves. Thank you all for your suggestions. Jul 16, 2019 at 9:53

1 Answer 1

0

I think your query should be something like this, Since you have a lookup to object B on A, you probably will start the relationship query from ObjB and downwards.

Select ObjAName, ObjB_r.ObjC_r.ObjD_r.ObjE_r.Name FROM ObjA

In the above query, Object B is my lookup field on Object A, Object C is my lookup field on Object B, and so on and so forth. So when I'm querying, will look down to the lookup fields from the Object I'm in. In his case, I'm looking at Object B from A and Object C from B downwards.

You must log in to answer this question.

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