Skip to main content
edited tags
Link
Adrian Larson
  • 151.4k
  • 38
  • 247
  • 431
Source Link

SOQL aggregate maxing out SOQL limits

I'm having trouble with my SOQL, running into SOQL limits in production. My SOQL is counting all active Users grouped by their Freeze status. How do I re-write the following SOQL without a subquery. Instead of a subquery I tried User.IsActive = true. That didn't work.

  SELECT count(Id) CountOfUsers,  IsFrozen FreezeStatus, max(LastModifiedDate) LastModified FROM UserLogin WHERE UserId IN 
                          (SELECT Id FROM User WHERE IsActive = true) group by IsFrozen.

Looks like the subquery is causing the max out eventhough I'm returning an aggregate of 2 rows.