SOQL Alias Support
Standard SOQL only lets you alias the result of an aggregate function, for example
SELECT COUNT(Id) total FROM Account. You cannot alias a plain field, a relationship field, or any other select
expression. Brobench removes that restriction — you can add an alias to virtually every kind of item in the
SELECT list, and Brobench renames the corresponding column in the results grid accordingly.
Syntax
The general form is:
<select expression> [as] <alias>
Whether the as keyword is required, optional, or not allowed depends on the kind of select expression:
| Select Expression | as keyword | Example |
|---|---|---|
| Base field | Required | Name as AccountName |
| Relationship field | Required | Owner.Name as OwnerName |
TYPEOF ... END polymorphic field | Required | TYPEOF What WHEN Account THEN Phone END as WhatPhone |
| Function (aggregate or non-aggregate) | Optional | SUM(Amount) as TotalAmount or SUM(Amount) TotalAmount |
Formula Columns have their own dedicated syntax ({{expr}}:type alias) — see that page for
details.
-
Aliasing is validated and applied per query level, so child (subquery)
SELECTlists can use their own aliases independently of the parent query. -
Aliasing a wildcard pattern (
*,billing*, etc.) is parsed but has no effect — a single wildcard can expand into many columns, so there's no single column for the alias to rename. See Wild Card Fields for more on wildcard selection.
Examples
| SOQL | Description |
|---|---|
SELECT Name as AccountName, Owner.Name as OwnerName FROM Account | Renames a base field and a relationship field in the results grid. |
SELECT StageName, TOLABEL(StageName) as StageLabel FROM Opportunity | Aliases a non-aggregate function so the label column has a friendly name. |
SELECT AccountId, SUM(Amount) TotalAmount FROM Opportunity GROUP BY AccountId | Aliases an aggregate function without using the as keyword. |
SELECT Id, (SELECT Name as ContactName FROM Contacts) FROM Account | Aliases a field inside a child (subquery) relationship query. |
SELECT TYPEOF What WHEN Account THEN Phone WHEN Contact THEN MobilePhone END as WhatPhone FROM Task | Aliases a polymorphic TYPEOF field. |