You need to sign in to do that
Don't have an account?

Governor limits for sub query in query locator (Batch apex)?
Hi,
I know that we can iterate at most 50M rows using query locator, does anybody have any idea about SOQL rows limit for sub query used in query locator?
Thanks in advance.
Thanks,
Lakhan
Hi,
By using below point you can understand
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.
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
All Answers
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm
Hi,
By using below point you can understand
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.
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
Thanks Hari for the quick response. Little bit worried about the query locator, should i move the sub queries in execute method to leverage the full capacity of query locator? what should be the best practise.
Hi,
Yes, as per the above points if you want to get the Full Capacity of Get Query locator (50M) then it is better to move to execute method.
Before going to this implementation:
FYI
You need to understand one more point.
Normally select query can get only 50,000 records, but get query locator can get 50M records.
So be cautious and plan your code/Query in Execute method accordingly.