# CRM Analytics in Apex

Build and execute queries and retrieve lens and template data using CRM Analytics Apex classes and methods.

CRM Analytics in Apex currently consists of the `executeQuery` method, the `Wave.QueryBuilder` class, and the `Wave.Lenses` class.

`ConnectApi.Wave.executeQuery`

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.

`Wave.QueryBuilder`

The `QueryBuilder` class is the most convenient, preferred, and safest way to construct a SAQL query string for execution.

`Wave.Lenses`

Retrieve a collection of CRM Analytics lens assets and describe a single lens asset.

`Wave.Templates`

Retrieve a collection of CRM Analytics templates, describe a single template and template configuration.

## Resources

For more information on using Apex, see the [Apex Developer Guide](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_reference.htm).

- **[CRM Analytics Apex Lens](/docs/analytics/bi-dev-guide-sdk/guide/bi-sdk-apex-lens.md)**

  Use the `Lenses` class to retrieve a collection of CRM Analytics lens assets and to describe a single lens asset.

- **[CRM Analytics Apex Query](/docs/analytics/bi-dev-guide-sdk/guide/bi-sdk-apex-query.md)**

  Query your data in CRM Analytics from any Apex class. Construct well-formed queries using the query builder.

- **[CRM Analytics Apex QueryBuilder Examples](/docs/analytics/bi-dev-guide-sdk/guide/bi-sdk-apex-examples.md)**

  Build simple or complex SAQL queries using QueryBuilder.

- **[CRM Analytics Apex Templates](/docs/analytics/bi-dev-guide-sdk/guide/bi-sdk-apex-templates.md)**

  Use the `Templates` class to retrieve a collection of CRM Analytics templates, describe a single template and template configuration.
