I have an account that has 626,482 opportunities spread over 1,368 owners.
In the Developer Console if I run the following Apex
List<SObject> recs = [select sum(amount), ownerid from opportunity group by ownerid];
I get the error:
System.LimitException: Too many query rows: 50001: AnonymousBlock: line 1, column 1
which I expect.
Still in the Developer Console if I now go to the Query Editor and run the SOQL
select sum(amount), ownerid from opportunity group by ownerid
it runs and returns back the 1,368 records.
No governor limit hit.
In case the Developer Console has a special “I’m Salesforce” meaning if I run this Javascript on a VisualForce page
function query() { jQuery.ajax('/services/data/v29.0/query/?q=' + encodeURIComponent('select sum(amount), ownerid from opportunity group by ownerid'), { type: 'GET', contentType: 'application/json', beforeSend: function(xhr) { // Set the OAuth header from the session ID xhr.setRequestHeader('Authorization', 'Bearer {!$Api.Session_ID}'); }, processData: false, dataType: 'json', success: function(response) { alert(response.records.length); }, error: function(jqXHR, textStatus, errorThrown) { // Oops - what went wrong? alert(jqXHR.status + ': ' + errorThrown); } }); }
it also works without hitting any governor limit.
I’m obviously missing which governor limit is being applied. Can someone point it out?
Answer
The API isn’t the same as Apex Code. In the API, you’ve a hard limit of 50,000,000 rows as an administrator, and up to approximately 1,000,000 rows as a non-administrator (because of sharing calculations, depending on the object and the object’s row count). The query editor is an API call, not an Apex Code call, and not subject to the limits of Apex Code. Specifying read-only on an Apex Class grants a new limit of 1,000,000 rows, but prohibits DML operations. Additionally, specifying read-only on the Visualforce page grants higher loop/collection limits, but restricts DML operations. Coincidentally, you can call the REST API through Apex Code to skirt around these limitations, assuming the running user has API access. The developer console uses executeAnonymous
for the Execute Apex Code window, but uses the normal REST API for the query editor, which explains the difference in behavior.
Attribution
Source : Link , Question Author : Stephen Roden , Answer Author : sfdcfox