Skip to content

soqlDatatable: Support for Aggregate Queries

James Hou edited this page Jan 24, 2021 · 1 revision

You can make use of valid aggregate queries to create dynamic rollup summaries, particularly when combined with the power of the $recordId bind variable on record flexipages, like showing a quick snapshot of Opportunity values:

soqlDatatable aggregate query example

soqlDatatable supports the following aggregate query methods:

  • avg
  • count
  • count_distinct
  • min
  • max
  • sum

The only aggregate query operation not supported is the raw count call (without a field API name specified), as this kind of query returns a number instead of AggregateResult SObjects:

--returns an integer
SELECT Count()
FROM User
WHERE Profile.Name = 'Standard User'

Invalid SOQL queries will be reported via toast message on the page the soqlDatatable is on.

Considerations

  • Aliases do not support spaces or dashes. Use underscores if needed (e.g. SUM(ExpectedRevenue) Revenue_Sum).
  • LIMIT clauses are not supported in aggregate queries without a GROUP BY clause.
  • You can alias column labels the same way that you can in SOQL: either with a space or without a space. avg(Id)myAvg and avg(Id) myAvg thus are both labeled myAvg within your datatable.
  • Non-aliased aggregate fields would typically be returned as expr0, expr1, etc — instead, we swap out these expr labels for the aggregate query in question: e.g. avg(Id) is labeled avg(Id) within your datatable.
  • Date Functions are supported.

Limitations

  • Using max/min with any Date or DateTime field does not currently display properly.
Clone this wiki locally