You need to sign in to do that
Don't have an account?

Ordered field must be grouped or aggregated
hi iam trying to group name and order by period but giving above error how can i do that
my query is:
my query is:
list<Agreement1__c> al = [select Name,driver__C,period__C,sales__c,quantity__c from Agreement1__C group By Name order by period__c ];please tell me how can delete that error
Make some change as shown below as underline, and let me know whether it solves your problem.
list<Agreement1__c> al = [select Name,driver__C,period__C,sales__c,quantity__c fromAgreement1__C group By Name, driver__C, period__C, sales__c, quantity__c order by period__c ];
Warm Regards,
Darshan Shah
bt it is giving an error like (Illegal assignment from List<AggregateResult> to List<gtms1__Agreement1__c>);
This query will return AggregateResult. you need to get values from that.
So change query as below and let me know whether it works for you or not.
List<AggregateResult> lstAggregateResult = [select Name, driver__C, period__C, sales__c, quantity__c fromAgreement1__C group By Name, driver__C, period__C, sales__c, quantity__c order by period__c ];
for (AggregateResult ar : lstAggregateResult)
{
/*Get values from AggregateResult*/
system.debug('===== Name:'+ar.get('Name'));
system.debug('===== sales__c:'+ar.get('sales__c'));
}
Warm Regards,
Darshan Shah
Kindly let me know whether above code is working or not.
If working then mark this question as SOLVED so other people can get help from this :)
Regards,
Darshan