0

There are 2 child objects for Account object, namely AccChild1 and AccChild2. Is it possible to traverse from AccChild2 to Account object, and then from Account to AccChild1 object in a single SOQL query?

This is something like: Child1 --> Parent --> Child2

0

1 Answer 1

1

Answer is yes, you can do it one soql.

List<Account> accts = [
    select Id, (
        select Id from AccChildren2__r
        )
    from Account
    where Id in (
        select Account__c from AccChild1__c
        )
    ];

for(Account acct :accts){
    List<AccChild2__c> children2 = acct.AccChildren2__r;
    //do something
}

Pay attention, that you need to specify correct child relationship name for AccChild2__c sobject from Account. refer to Understanding Relationship Names, Custom Objects, and Custom Fields

You must log in to answer this question.

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