0

how can i query non grouped field values using soql.

Example: Select Macro.name,count(MacroId),target,value from MacroInstruction GROUP BY Macro.name HAVING count(MacroId)>1

i need target and value fields values?

when i tried developer console am getting this error

MALFORMED_QUERY
[object Object]: Field must be grouped or aggregated: Target
0

Try Below Query:

Select Macro.name,target,count(MacroId) from MacroInstruction where target!='' or target='' 
GROUP BY Macro.name,target HAVING count(MacroId)>1

Whenever you use aggregate function like Count(),Sum() etc,all other fields must be grouped.

If you can see in the above query,I am not querying on 'Value' field because as per Considerations When Using GROUP BY

Some object fields have a field type that does not support grouping. You can't include fields with these field types in a GROUP BY clause. The Field object associated with DescribeSObjectResult has a groupable field that defines whether you can include the field in a GROUP BY clause.

Check the below link:

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_describesobjects_describesobjectresult.htm#field_groupable

Hence Remove the Value field and check if you get the result.

| improve this answer | |
  • but above query macro.name field dupilcates showing, i want to prevent macro names. my main requirement is i want to prevent duplicates Macro.name field at the same time i need to query target and value fields – Sfdcprgmr Nov 13 '17 at 12:47
  • In soql,we don't have DISTINCT keyword that removes the duplicate.In order to prevent duplicates,you need to use Map or Set to check the unique result.If you want to query on Value field then you need to remove Group By Clause. – Dhananjay Patil Nov 13 '17 at 12:56
  • we have COUNT_DISTINCT keyword. i want to export macros with macroinstruction. so not possible to use set or map. so i need exact query result without duplicates: Select Macro.name,macroid,target,value from MacroInstruction – Sfdcprgmr Nov 13 '17 at 13:16

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.