Skip to content

QRY_Condition.DateLiteral ​

Class · Group: Query Infrastructure

Learn it: Fast Start - Selectors and Selectors guide

apex
global inherited sharing class QRY_Condition.DateLiteral implements QRY_Condition.Evaluable

Implements: QRY_Condition.Evaluable

Provides SOQL date literal values for use in QRY_Builder conditions. Implements Evaluable so date literals can be passed as condition values to FieldCondition and through the QRY_Builder fluent API. Date literals are special SOQL keywords (TODAY, LAST_N_DAYS:30, etc.) that represent relative date/time ranges and cannot be expressed as bind variables.

Example

apex
// Records created in the last 30 days
List<Account> accounts = QRY_Builder.selectFrom(Account.SObjectType)
    .condition('CreatedDate').equals(new QRY_Condition.DateLiteral().lastNDays(30))
    .toList();
// Records created today
List<Account> accounts = QRY_Builder.selectFrom(Account.SObjectType)
    .condition('CreatedDate').equals(new QRY_Condition.DateLiteral().today())
    .toList();

Methods ​

MethodDescription
global QRY_Condition.DateLiteral last(Integer numberOfUnits, QRY_Condition.UnitOfTime unit)Sets the date literal to LAST_N_*:n.
global QRY_Condition.DateLiteral last(QRY_Condition.UnitOfTime unit)Sets the date literal to LAST_* for a given unit (e.g., LAST_QUARTER).
global QRY_Condition.DateLiteral last90Days()Matches today and the 90 days before it, with the SOQL keyword LAST_90_DAYS.
global QRY_Condition.DateLiteral lastNDays(Integer numberOfDays)Matches today and the n days before it, written as LAST_N_DAYS:n (lastNDays(30) writes LAST_N_DAYS:30).
global QRY_Condition.DateLiteral next(Integer numberOfUnits, QRY_Condition.UnitOfTime unit)Sets the date literal to NEXT_N_*:n.
global QRY_Condition.DateLiteral next(QRY_Condition.UnitOfTime unit)Sets the date literal to NEXT_* for a given unit (e.g., NEXT_QUARTER).
global QRY_Condition.DateLiteral next90Days()Matches the next 90 days, starting tomorrow, with the SOQL keyword NEXT_90_DAYS.
global QRY_Condition.DateLiteral nextNDays(Integer numberOfDays)Matches the next n days, starting tomorrow, written as NEXT_N_DAYS:n (nextNDays(60) writes NEXT_N_DAYS:60).
global QRY_Condition.DateLiteral thisUnit(QRY_Condition.UnitOfTime unit)Matches the current week, month, quarter, year, fiscal quarter or fiscal year, written as THIS_ and the unit name, such as THIS_MONTH.
global QRY_Condition.DateLiteral today()Matches the whole of today, with the SOQL keyword TODAY.
global QRY_Condition.DateLiteral tomorrow()Matches the whole of the day after today, with the SOQL keyword TOMORROW.
global QRY_Condition.DateLiteral yesterday()Matches the whole of the day before today, with the SOQL keyword YESTERDAY.

last ​

apex
global QRY_Condition.DateLiteral last(Integer numberOfUnits, QRY_Condition.UnitOfTime unit)

Sets the date literal to LAST_N_*:n.

Parameters

ParameterTypeDescription
numberOfUnitsIntegerThe number of units
unitQRY_Condition.UnitOfTimeThe unit of time

Returns QRY_Condition.DateLiteral — The DateLiteral instance for method chaining.

Example

apex
new QRY_Condition.DateLiteral().last(4, QRY_Condition.UnitOfTime.QUARTER)
apex
global QRY_Condition.DateLiteral last(QRY_Condition.UnitOfTime unit)

Sets the date literal to LAST_* for a given unit (e.g., LAST_QUARTER).

Parameters

ParameterTypeDescription
unitQRY_Condition.UnitOfTimeThe unit of time

Returns QRY_Condition.DateLiteral — The DateLiteral instance for method chaining.

Example

apex
new QRY_Condition.DateLiteral().last(QRY_Condition.UnitOfTime.QUARTER)

last90Days ​

apex
global QRY_Condition.DateLiteral last90Days()

Matches today and the 90 days before it, with the SOQL keyword LAST_90_DAYS. lastNDays(90) writes the same keyword.

Returns QRY_Condition.DateLiteral — The DateLiteral instance for method chaining.

Example

apex
new QRY_Condition.DateLiteral().last90Days()

lastNDays ​

apex
global QRY_Condition.DateLiteral lastNDays(Integer numberOfDays)

Matches today and the n days before it, written as LAST_N_DAYS:n (lastNDays(30) writes LAST_N_DAYS:30). For 90 it writes LAST_90_DAYS. A negative number throws IllegalArgumentException.

Parameters

ParameterTypeDescription
numberOfDaysIntegerThe number of days

Returns QRY_Condition.DateLiteral — The DateLiteral instance for method chaining.

Example

apex
new QRY_Condition.DateLiteral().lastNDays(30)

next ​

apex
global QRY_Condition.DateLiteral next(Integer numberOfUnits, QRY_Condition.UnitOfTime unit)

Sets the date literal to NEXT_N_*:n.

Parameters

ParameterTypeDescription
numberOfUnitsIntegerThe number of units
unitQRY_Condition.UnitOfTimeThe unit of time

Returns QRY_Condition.DateLiteral — The DateLiteral instance for method chaining.

Example

apex
new QRY_Condition.DateLiteral().next(2, QRY_Condition.UnitOfTime.FISCAL_YEAR)
apex
global QRY_Condition.DateLiteral next(QRY_Condition.UnitOfTime unit)

Sets the date literal to NEXT_* for a given unit (e.g., NEXT_QUARTER).

Parameters

ParameterTypeDescription
unitQRY_Condition.UnitOfTimeThe unit of time

Returns QRY_Condition.DateLiteral — The DateLiteral instance for method chaining.

Example

apex
new QRY_Condition.DateLiteral().next(QRY_Condition.UnitOfTime.QUARTER)

next90Days ​

apex
global QRY_Condition.DateLiteral next90Days()

Matches the next 90 days, starting tomorrow, with the SOQL keyword NEXT_90_DAYS. nextNDays(90) writes the same keyword.

Returns QRY_Condition.DateLiteral — The DateLiteral instance for method chaining.

Example

apex
new QRY_Condition.DateLiteral().next90Days()

nextNDays ​

apex
global QRY_Condition.DateLiteral nextNDays(Integer numberOfDays)

Matches the next n days, starting tomorrow, written as NEXT_N_DAYS:n (nextNDays(60) writes NEXT_N_DAYS:60). For 90 it writes NEXT_90_DAYS. A negative number throws IllegalArgumentException.

Parameters

ParameterTypeDescription
numberOfDaysIntegerThe number of days

Returns QRY_Condition.DateLiteral — The DateLiteral instance for method chaining.

Example

apex
new QRY_Condition.DateLiteral().nextNDays(60)

thisUnit ​

apex
global QRY_Condition.DateLiteral thisUnit(QRY_Condition.UnitOfTime unit)

Matches the current week, month, quarter, year, fiscal quarter or fiscal year, written as THIS_ and the unit name, such as THIS_MONTH. DAY gives TODAY, because SOQL has no THIS_DAY. A null unit throws a NullPointerException.

Parameters

ParameterTypeDescription
unitQRY_Condition.UnitOfTimeThe unit of time

Returns QRY_Condition.DateLiteral — The DateLiteral instance for method chaining.

Example

apex
new QRY_Condition.DateLiteral().thisUnit(QRY_Condition.UnitOfTime.MONTH)
new QRY_Condition.DateLiteral().thisUnit(QRY_Condition.UnitOfTime.DAY)  // returns TODAY

today ​

apex
global QRY_Condition.DateLiteral today()

Matches the whole of today, with the SOQL keyword TODAY. Pass the result as a condition value, for example to equals(). It replaces any date set earlier on this object.

Returns QRY_Condition.DateLiteral — The DateLiteral instance for method chaining.

Example

apex
new QRY_Condition.DateLiteral().today()

tomorrow ​

apex
global QRY_Condition.DateLiteral tomorrow()

Matches the whole of the day after today, with the SOQL keyword TOMORROW. Pass the result as a condition value, for example to equals(). It replaces any date set earlier on this object.

Returns QRY_Condition.DateLiteral — The DateLiteral instance for method chaining.

Example

apex
new QRY_Condition.DateLiteral().tomorrow()

yesterday ​

apex
global QRY_Condition.DateLiteral yesterday()

Matches the whole of the day before today, with the SOQL keyword YESTERDAY. Pass the result as a condition value, for example to equals(). It replaces any date set earlier on this object.

Returns QRY_Condition.DateLiteral — The DateLiteral instance for method chaining.

Example

apex
new QRY_Condition.DateLiteral().yesterday()