QRY_Builder.AggregateRow
Class · Group: Query Infrastructure
Learn it: Fast Start - Selectors and Selectors guide
global inherited sharing class QRY_Builder.AggregateRowTyped wrapper around AggregateResult for convenient value access. Provides typed accessors that eliminate the need for manual casting from Object. In a test, a row can also hold the values of a row registered with TST_Mock.registerAggregateRows or QRY_Builder.setAggregateMock. Such a row answers as a real row does: an alias is matched without regard to case, and reading an alias the row does not hold throws IllegalArgumentException. Its number getters also accept a whole number written as an Integer, a Long or a Decimal.
Example
QRY_Builder.AggregateRow row = QRY_Builder.selectFrom(Account.SObjectType)
.count(Account.Id, 'total')
.groupBy(Account.Industry)
.toAggregateList()[0];
Integer total = row.getInteger('total');
String industry = row.getString('Industry');Methods
| Method | Description |
|---|---|
| global Object get(String alias) | Gets a raw Object value by alias. |
| global Date getDate(String alias) | Reads a date, such as the MIN or MAX of a date field. |
| global Decimal getDecimal(String alias) | Reads a number with decimals, such as the SUM or AVG of an amount. |
| global Id getId(String alias) | Reads a record Id, such as a grouped lookup field. |
| global Integer getInteger(String alias) | Reads a whole number, such as a COUNT. |
| global Long getLong(String alias) | Reads a whole number as a Long. |
| global String getString(String alias) | Reads a text value, such as a grouped text or picklist field. |
get
global Object get(String alias)Gets a raw Object value by alias.
Parameters
| Parameter | Type | Description |
|---|---|---|
alias | String | The aggregate alias or field name |
Returns Object — The raw value
Example
QRY_Builder.AggregateRow row = QRY_Builder.selectFrom(Opportunity.SObjectType)
.sum(Opportunity.Amount, 'total')
.getFirstAggregate();
Object value = row.get('total');getDate
global Date getDate(String alias)Reads a date, such as the MIN or MAX of a date field. Returns null when the row holds null under the alias.
Parameters
| Parameter | Type | Description |
|---|---|---|
alias | String | The aggregate alias or field name |
Returns Date — The Date value
Example
QRY_Builder.AggregateRow row = QRY_Builder.selectFrom(Opportunity.SObjectType)
.min(Opportunity.CloseDate, 'earliest')
.getFirstAggregate();
Date earliest = row.getDate('earliest');getDecimal
global Decimal getDecimal(String alias)Reads a number with decimals, such as the SUM or AVG of an amount. Returns null when the row holds null under the alias.
Parameters
| Parameter | Type | Description |
|---|---|---|
alias | String | The aggregate alias or field name |
Returns Decimal — The Decimal value
Example
QRY_Builder.AggregateRow row = QRY_Builder.selectFrom(Opportunity.SObjectType)
.sum(Opportunity.Amount, 'total')
.getFirstAggregate();
Decimal total = row.getDecimal('total');getId
global Id getId(String alias)Reads a record Id, such as a grouped lookup field. A grouped field with no alias is read by its field name, such as 'AccountId'. Returns null when the row holds null under the alias.
Parameters
| Parameter | Type | Description |
|---|---|---|
alias | String | The aggregate alias or field name |
Returns Id — The Id value
Example
Id accountId = row.getId('AccountId');getInteger
global Integer getInteger(String alias)Reads a whole number, such as a COUNT. A row that a test registered with TST_Mock.registerAggregateRows may hold the number as a Long or a Decimal; a whole number held either way is converted to an Integer, and a number with a fraction, such as 2.5, throws a TypeException. Returns null when the row holds null under the alias.
Parameters
| Parameter | Type | Description |
|---|---|---|
alias | String | The aggregate alias or field name |
Returns Integer — The Integer value
Example
QRY_Builder.AggregateRow row = QRY_Builder.selectFrom(Opportunity.SObjectType)
.count(Opportunity.Id, 'total')
.getFirstAggregate();
Integer count = row.getInteger('total');getLong
global Long getLong(String alias)Reads a whole number as a Long. A value held as an Integer, such as a COUNT, is returned as a Long too. Returns null when the row holds null under the alias.
Parameters
| Parameter | Type | Description |
|---|---|---|
alias | String | The aggregate alias or field name |
Returns Long — The Long value
Example
QRY_Builder.AggregateRow row = QRY_Builder.selectFrom(Opportunity.SObjectType)
.count(Opportunity.Id, 'total')
.getFirstAggregate();
Long total = row.getLong('total');getString
global String getString(String alias)Reads a text value, such as a grouped text or picklist field. A grouped field with no alias is read by its field name, such as 'Industry'. Returns null when the row holds null under the alias.
Parameters
| Parameter | Type | Description |
|---|---|---|
alias | String | The aggregate alias or field name |
Returns String — The String value
Example
String industry = row.getString('Industry');