0

can anyone explain it to me, why my query is error? here my query :

        PYEMPELEMENT__c[] VFLDLSTEmpSeparated = [SELECT Employee_No__c, Period__c FROM PYEMPELEMENT__c GROUP BY Employee_No__c, Period__c LIMIT 1];
1
  • This is not a very well formed question. You should always include the verbatim error message when you encounter an error. Glad to see you got the problem solved but there is still room for improvement.
    – Adrian Larson
    Sep 30, 2016 at 14:43

2 Answers 2

2

You need to change it

List<AggregateResult > VFLDLSTEmpSeparated = [SELECT Employee_No__c, Period__c FROM PYEMPELEMENT__c GROUP BY Employee_No__c, Period__c LIMIT 1];

When we use group by and other aggregate function we will get List<AggregateResult > so instead of sObject list we need to use this list and then we can parse the result

2
  • if i want to use VFLDLSTEmpSeparated.Employee_No__c in other method, how to store Employee_No__c field into variable? @TusharSharma
    – Vikolai
    Sep 30, 2016 at 10:34
  • @Vikolai VFLDLSTEmpSeparated[0].get('Employee_No__c') Sep 30, 2016 at 11:33
0

You are right Tushar, we need AggregateResult List. And to fetch the values you can later cast the AggregateResult

Set<Integer> empNumber = new Set<Integer>();  
for (AggregateResult results : [SELECT Employee_No__c, Period__c FROM PYEMPELEMENT__c GROUP BY Employee_No__c, Period__c LIMIT 1]){
    empNumber.add((Integer)results.get('Employee_No__c'));
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .