I have written the below web service class to return record count. But it is returning the following message "System.LimitException: Too many query rows: 50001". How could I overcome this limit?
@RestResource(urlMapping='/count/*')
global with sharing class GetCount{
@HttpGet
global static String doCount() {
RestRequest req = RestContext.request;
String objName = req.requestURI.split('/')[2];
String whereClause = EncodingUtil.urlDecode(req.requestURI.split('/')[3],'UTF-8');
return database.countQuery('SELECT COUNT() FROM ' + objName + ' WHERE ' + whereClause);
}
}