1

I am running an apex test and getting the following error:

System.QueryException: unexpected token: results

What I do not understand is that I am running this query in another one of my classes and it works perfectly. The only difference is that this query includes a group by clause. Not sure why the grouping would initiate this error? Is this because I am using a group by within a dynamic soql call?

 String contactsWorked_lastWeek  = 'SELECT count(id) results, account.SDR_Owner__c SDR results from contact where LastActivityDate = last_week AND account.RecordTypeid != \'0126A000000ytERQAY\' group by account.SDR_Owner__c';

lastWeek_queries.add(contactsWorked_lastWeek);

List<AggregateResult> contactsWorked_lastWeek = Database.query(queries[0]);

VS

String contactsWorked_lastWeek  = 'select count(id) results from contact where LastActivityDate = last_week AND account.RecordTypeid != \'0126A000000ytERQAY\'';

 lastWeek_queries.add(contactsWorked_lastWeek);

List<AggregateResult> contactsWorked_lastWeek = Database.query(queries[0]);
4

Query #1:

'SELECT count(id) results, account.SDR_Owner__c SDR results from contact where LastActivityDate = last_week AND account.RecordTypeid != \'0126A000000ytERQAY\' group by account.SDR_Owner__c';

has a double alias:

account.SDR_Owner__c SDR results

remove the spurious word "results" here and this one should work.

Query #2:

... is fine, because it's a count() query. Please excuse my brain-slippage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.