This is actually more involved than just replacing the selectFields with "count(1) as record_count". Once you have HAVING filters, etc (PRESIDECMS-646). you will need a subquery, so: