Only Aggregate Expressions Use Field Aliasing – SOQL Error
Out of many other errors we encounter, this is one with the SOQL. Many times, when writing SOQL, we face the error – “Only Aggregate Expressions Use Field Aliasing” and we are stuck that what’s happening, everything seems all right to me.
You must be missing a comma in the SOQL between two fields before FROM keyword.
Aliasing is when you want to give some different name to the column in any SOQL result, but you can only do so in aggregate queries of Salesforce, where you use some aggregate functions like sum(Custom_Field__c), count(Id) or any other similar aggregate function.
Below is a valid SOQL using aggregate function with aliasing. We are trying to give “amountTotal” name to Sum(Amount) column.
[Select Sum(Amount) amountTotal, AccountId from Opportunity group by AccountId];
BUT, because aliasing is not allowed in normal SOQL, that is why below SOQL is considered faulty, and will encounter the error “Only Aggregate Expressions Use Field Aliasing”.
[select id, Name Amount from Opportunity];
You might notice we are missing a comma between Name & Amount field, which is why Salesforce thinks that we are trying to give a different label to Name column in SOQL result but that is not allowed.
If you ever encounter this error in future, look for missing comma between two fields in your SOQL.
Happy coding !! 🙂
7 comments
1 ping
Skip to comment form
Thanks for this blog!!
It was really helpful 🙂
Thanks for this post and solved my error in seconds
very helpful. fixed my issue
great ….
Thanks — super helpful!
Very Helpfull sir
Thanks for this post….Super helpful!
I enjoyed your wonderful blog.
Thank you for the very hard work done.