Activity › Forums › Salesforce® Discussions › What is the governor limits of sub query in SOQL?
Tagged: Governor Limits, Help & Training, Limits, Nested Query, Salesforce Customization, Salesforce Development, SOQL, SOQL Query, Sub Query
-
What is the governor limits of sub query in SOQL?
Posted by saloni gupta on July 13, 2017 at 12:38 PMIn the nested query, what is the Salesforce governor limits of sub query in SOQL?
shariq replied 7 years, 7 months ago 5 Members · 4 Replies -
4 Replies
-
Hello Saloni,
In a SOQL query with parent-child relationship subqueries, each parent-child relationship counts as an extra query. These types of queries have a governor limit of three times the number for top-level queries. The row counts from these relationship queries contribute to the row counts of the overall code execution.
-
This reply was modified 8 years, 10 months ago by
Aman.
-
This reply was modified 8 years, 10 months ago by
- [adinserter block='9']
-
Hello Saloni,
By using below points you can understand Salesforce governor limits of sub query in SOQL:
In a SOQL query with parent-child relationship sub-queries, each parent-child relationship counts as an additional query. These types of queries have a limit of three times the number for top-level queries.
The row counts from these relationship queries contribute to the row counts of the overall code execution.
In addition to static SOQL statements, calls to the following methods count against the number of SOQL statements issued in a request.
Database.countQuery
Database.getQueryLocator
Database.query
From above statement i can clarify one point:For example your org contain only 2 Account and each have 10 Contacts.
If you execute this with sub Query like below
Select Id, Name, (Select Id, Name from Contacts) From Account
Then the total number of Query rows will be 22 (2+10+10).
From above analogy we can understand like this
If your org contain 40M accounts and each have 1 contact.
Then in this scenario you can use sub query up to 25M only.
Like this Select Id, Name, (Select Id, Name from Contacts) From Account limit 25M
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm
-
This reply was modified 8 years, 10 months ago by
Radhakrishna.
-
This reply was modified 8 years, 10 months ago by
-
Adding some points:
In a SOQL query with parent-child relationship sub-queries, each parent-child relationship counts as an additional query. These types of queries have a limit of three times the number for top-level queries.
The row counts from these relationship queries contribute to the row counts of the overall code execution.
In addition to static SOQL statements, calls to the following methods count against the number of SOQL statements issued in a request.
Database.countQuery
Database.getQueryLocator
Database.query
From above statement i can clarify one point:For example your org contain only 2 Account and each have 10 Contacts.
If you execute this with sub Query like below
Select Id, Name, (Select Id, Name from Contacts) From Account
Then the total number of Query rows will be 22 (2+10+10).
From above analogy we can understand like this
If your org contain 40M accounts and each have 1 contact.
Then in this scenario you can use sub query up to 25M only.
Like this Select Id, Name, (Select Id, Name from Contacts) From Account limit 25M
Thanks
-
Hi,
Note – Each parent-child relationship adds up to an additional query.
Hope this helps.
Log In to reply.