+ Start a Discussion
Nandika Kodituwakku 10Nandika Kodituwakku 10 

how to Alias a column in SOQL

Hi Devs,

How do we something simple like below in SOQL.


Vikas gupta 24Vikas gupta 24
Hi Nandika,

you can't create alisa on field, in salesforce it is allow only with the aggregate function. like below
select count(id) Total from opportunity

In above it will create default alias expr0 to total. 

Thanks, Vikas
SOQL has very limited aliasing support. You can alias the table, e.g. SELECT a.name FROM Account a, but that's of very little use. In most contexts you cannot alias fields.
The one exception is for queries that use aggregations, like SELECT COUNT(Id) recordCount FROM Account allows you to alias the result of the aggregation from it's default expr0 to recordCount.
Sunil Shah 12Sunil Shah 12
Thanks Vineet :)
Jeremy West 15Jeremy West 15
Wow... that is irritating. 

So we have to change all our code downstream whenever we make a change to underlying data structure?