12

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?

1 Answer 1

18

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).

5
  • But would this be a hack to do a "SELECT Count() FROM Account LIMIT 50001" in Apex using the Tooling API? Commented Feb 21, 2017 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
    Commented Feb 21, 2017 at 16:25
  • 1
    Though with VF, you can use the readonly mode to get 1 million rows I think? Commented Feb 21, 2017 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
    Commented Feb 21, 2017 at 17:29
  • @sfdcfox - agreed, though that point, I think it is time to look at Batch or something else... Commented Feb 21, 2017 at 17:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .