Salesforce has governor limits, I understand. But it is frustrating when the methods for checking limits throws an exception that it is exceeding limits.
For example:
System.QueryException: Aggregate query has too many rows for direct assignment, use FOR loop
And this:
System.QueryException: Aggregate query has too many rows for direct assignment, use FOR loop
And this:
System.Exception: Too many query rows: 10001
Then assigning the rows within the loop like this:
INVALID_QUERY_LOCATOR: invalid query locator
This looks pretty hopeless - can't exceed limits, and there's no way to check if we're exceeding limits.
There are actually several possibilities for this sequence of errors:
Best Practices:
For example:
if(myList.size()>=Limits.getLimitQueryLocatorRows())throws this error:
System.QueryException: Aggregate query has too many rows for direct assignment, use FOR loop
And this:
if(u.Tasks!=null)throws this error:
System.QueryException: Aggregate query has too many rows for direct assignment, use FOR loop
And this:
SELECT count() FROM myObjectthrows this error:
System.Exception: Too many query rows: 10001
Then assigning the rows within the loop like this:
for( MyChild__c c : parent.MyChild__r )throws this error:
INVALID_QUERY_LOCATOR: invalid query locator
This looks pretty hopeless - can't exceed limits, and there's no way to check if we're exceeding limits.
There are actually several possibilities for this sequence of errors:
- You really do have too much data for a single query
- There's a null somewhere, most likely the parent record is null. This could be a result of #4 below. A queryLocator is not available indefinitely.
- You've exceeded your allowance of having max 5 queryLocators open. The 5 cursor limit is per userId, not per session.
- You've exceeded 10 minute inactivity timeout of a queryLocator
- Checking for "done" invalidates the queryLocator
Best Practices:
- Call queryMore at least every 15 minutes to keep the cursor alive, otherwise the queryLocator gets invalidated
- Check your queryLocator value before and after each call
- If you know your Ids prior, use the retrieve call instead.
No comments:
Post a Comment