+ Start a Discussion
WesNolte__cWesNolte__c 

SOQL Governor limits on nested queries

Hello

 

I've noticed some inconsistencies so I'm a little confused as to what I should believe. The type of code in question might be:

 

 

for(Account a: [SELECT id, (SELECT id FROM Contact) FROM Account]){
// TODO
}

 If I run this query in an anonymous block the profile information says that I've only run one query. If I use this in my Apex code I very quickly hit the query limit. According to the documentation:

 

2 In a SOQL query with parent-child relationship sub-queries, each parent-child relationship counts as an additional query.

 

Has anyone else experienced this? I assume that the documentation is right, but am I interpreting it correctly i.e. I think it means that for each account record that is selected in the above query an addition query is run for it's child contacts. So if I had 2 Accounts with a contact each I would incur a cost of 3 querys.

 

Wes

 

 

TehNrdTehNrd

I think the documenation is wrong. If your example of 3 SOQLs was true you would only be able to query 20 children which I know for a fact you can query much more.

 

I'm pretty sure it counts as 1 SOQL statement.