I have two objects (Test1 and Test2) which have a lookup relationship to "Test 3".

I need a single query to fetch the test1, test2 records by test 3 ID. Heres what I've tried:

select id, name from test1, (select id, name from test2) where test3='3123'

You can write like this:

In your case "Test3" is parent,"test1" and "test2" are childs.

Try below query,

[select id,name,(select id,name from test1s__r),(select id,name from test2s__r) from test3__c]

For Example

 SELECT id,(SELECT Id,Status,CaseNumber FROM Cases),(SELECT Id,Name FROM Contacts) FROM Account 
| improve this answer | |
  • Yes this is the way you can get multiple child records. Note that here you can see __r instead of __c that's because tfor relationship query you need to mention __r for related object records – Mustafa Jhabuawala Nov 29 '17 at 16:57
  • thanks for that.i need these data in EXCEL format .how can i get it – sandy Nov 30 '17 at 5:51
  • This is the same requirement where i need the above query result in Excel format – sandy Nov 30 '17 at 6:48
  • No i need a result needs to be come in excel without copy paste of data – sandy Nov 30 '17 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.