[SalesForce] “System.LimitException: Too many query rows: 50001” in count query

I am getting this error in this line

list<AggregateResult> LstTicketPreEmpCases = new list<AggregateResult>();
        LstTicketPreEmpCases = [SELECT Highest_Charge_Level__c, count(id)NoofCharge,COUNT_DISTINCT(PreEmploy_Case__r.name)NoofCases FROM BGC_Criminal_Search_Record__c
        GROUP BY Highest_Charge_Level__c LIMIT 1000];

I have reduced limit to 10 but still I'm getting this error but when I'm using LIMIT 1 than it works.

Best Answer

Finally i got error it was from visualforce page. I have fixed it by applying readOnly="true"