4

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'
1

1 Answer 1

14

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 
4
  • 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 Commented Nov 29, 2017 at 16:57
  • thanks for that.i need these data in EXCEL format .how can i get it
    – sandy
    Commented Nov 30, 2017 at 5:51
  • This is the same requirement where i need the above query result in Excel format
    – sandy
    Commented Nov 30, 2017 at 6:48
  • No i need a result needs to be come in excel without copy paste of data
    – sandy
    Commented Nov 30, 2017 at 10:42

You must log in to answer this question.

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