CRM Analytics Apex Query
Query your data in CRM Analytics from any Apex class. Construct well-formed queries using the query builder.
The Apex SDK query features include the executeQuery method and the Wave.QueryBuilder class.
ConnectApi.Wave.executeQuery
At its simplest, use the executeQuery function (exposed through the ConnectApi namespace) to pass a SAQL query from an Apex page to CRM Analytics, and get a response in the form of JSON. For example, this sample sends ‘your SAQL query’ to CRM Analytics.
Sending queries like this is useful, but relies on the developer coding well-formed SAQL queries. Wouldn’t it be great if a class constructed the queries for you?
Wave.QueryBuilder
The Wave.QueryBuilder class is the most convenient, preferred, and safest way to construct a SAQL query string for execution. It’s not an exhaustive implementation of all possible SAQL queries—so sometimes you must write your own—but it does cover the vast majority of use cases, including:
-
load dataset statement
-
foreach statement
-
group statement
-
order statement
-
limit statement
-
filter statement
-
functions such as min, max, count, avg, unique, as, sum
Use Wave.QueryBuilder and its associated classes, Wave.ProjectionNode and Wave.QueryNode, to incrementally build your SAQL statement. For example: