For years people were looking for ways to query more than 50.000 records in Salesforce without running into Too many query rows: 50001. Event doing a COUNT() query was impossible.

By accident, I just did a query on a type with more than 1 million records. In the Query Editor of the Dev Console. And it worked!

When I tried the same in Apex it failed as expected. Why?


Apex uses more resources than a simple API call, such as extra memory, CPU time, etc, so there's additional limits in place. The Developer Console, contrariwise, uses the API, which is just a server-side database cursor. As such, you can technically query up to 50,000,000 rows in the Developer Console (though very large queries may time out or freeze your browser).

  • But would this be a hack to do a "SELECT Count() FROM Account LIMIT 50001" in Apex using the Tooling API? – Robert Sösemann Feb 21 '17 at 16:11
  • 1
    @RobertSösemann You could do it in certain contexts, but you might get a recursive callout error or a DML not committed error. It's probably safe in Visualforce contexts, though, if you wanted to. – sfdcfox Feb 21 '17 at 16:25
  • 1
    Though with VF, you can use the readonly mode to get 1 million rows I think? – BritishBoyinDC Feb 21 '17 at 17:21
  • @BritishBoyinDC Certainly, but then you're in read-only mode. So it might be useful if you need to write data back later, or need to get more than 1 million rows, etc. – sfdcfox Feb 21 '17 at 17:29
  • @sfdcfox - agreed, though that point, I think it is time to look at Batch or something else... – BritishBoyinDC Feb 21 '17 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.