4

I have 26 accounts and 24 contact records in the org and running a SOQL query on them (fetching Accounts along with contacts). Found that if SOQL for loop is used then the child records fetched in the query don't contribute to the governor limit (refer to screenshot below) unlike standard SOQL queries.

SOQL for loop:

for(Account a : [Select Id, Name, (Select Id, Name from Contacts) From Account]) {}

The number of query rows counted is :

enter image description here

Standard SOQL query:

List<Account> acc = [Select Id, Name, (Select Id, Name from Contacts) From Account];

The number of query rows counted is : enter image description here

I tried finding this in documentation, but couldn't find it. Can someone please validate if my observation is correct or not?

1
  • 1
    I'm seeing the same results in both a sandbox and production. I tried what happens when the combined account and contacts rows go over 50.000 and then it still only shows the account query rows. It also works if you iterate over List<Account> instead of a single account.
    – Kasper
    Jan 30, 2022 at 16:52

1 Answer 1

-1

This seems to be consistent to what the documentation shows about avoiding heap limits and the way the data is retrieved. Specifically it looks like the queryMore function is used.

1
  • 1
    I don't see where that mentions that the query rows of the subquery don't count for the total number of query rows. Could you perhaps add that to your answer?
    – Kasper
    Jan 30, 2022 at 16:52

You must log in to answer this question.

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