I realize that this is a very basic exception but I don't understand why it is being thrown although I am limiting the number of results to 10,000. My question is similar to this post but nothing there helps. I also looked at this. Here is my query/code:
Map<Id, LoginGeo> location_dump = new Map<Id, LoginGeo>(); for(LoginGeo lg : [SELECT Id, City, Country, CountryIso, latitude, longitude, PostalCode, LoginTime, Subdivision FROM LoginGeo WHERE Id IN :geo_ids ORDER BY LoginTime DESC LIMIT 10000]) location_dump.put(lg.Id, lg);
geo_ids is a
Set<Id> containing ids of type
Why is it pulling 50,000+ records?
System.LimitException: Too many query rows: 50001 exception for that query.
Might be helpful:
- This will work only on API version 35.0 and above.
- The query alone returns exactly 10000 records, like it should, in Developer Console.
- The exception is thrown in a test method while deploying it to Production org. This works super fine in my sandbox, because the data there is limited.
- Fortunately for me these are standard objects, so you can try it in your orgs if at all.