Templates Class

The Templates class provides methods for retrieving CRM Analytics template collections, individual templates, and template configurations.

Namespace

Wave

Usage

Use Templates and its associated class Wave.TemplatesSearchOptions to get CRM Analytics template information.

Examples

This code sample declares a method that returns a list of the template names.

@AuraEnabled(cacheable=true)
public static void List<String> getTemplateNames() {
  Map<String, Object> o = Wave.Templates.getTemplates(new Wave.TemplatesSearchOptions());
  List<Object> templates = (List<Object>) o.get('templates');
  List<String> names = new List<String>();
  for (Object templateObj : templates) {
    names.add((String) ((Map<String, Object>) templateObj.get('name'));
  }
  return names;
}

Adding the @AuraEnabled annotation allows Lightning Web Components to access Templates methods directly.

For example, in the lwc.js file:

import getTemplates from '@salesforce/apex/Wave.Templates.getTemplates';
export default class Templates extends LightningElement {
  @wire(getTemplates, {
    // specifying 'options' is optional
    options: {
      // values in TemplatesSearchOptions go here; all optional
      type: 'app'
    }
  })
  onTemplates({ data, error }) {
    if (data) {
      console.log('template names=' + data.templates.map(l => l.name).join(', '));
    }
  }
}

Templates Methods

The following are methods for Templates.

getTemplate(templateIdOrApiName)

Gets a CRM Analytics template by the specified ID or API name. The returned template is a map of the template JSON attributes as name/value pairs.

Signature

public static Map<String,Object> getTemplate(String templateIdOrApiName)

Parameters

  • templateIdOrApiName:

    Type: String

    The template ID or API name of the template to retrieve.

Return Value

Type: Map<String,Object>

A map of the template JSON attribute name/value pairs, where the name is a string with an object value. For attributes details, see TemplateRepresentation.

Example

String templateName = (String) Wave.Templates.getTemplate(templateId).get('name');

Here, templateId is a placeholder value.

getTemplateConfig(templateIdOrApiName)

Gets the CRM Analytics template configuration by the specified ID or API name. The returned template configuration is a map of the JSON attributes as name/value pairs.

Signature

public static Map<String,Object> getTemplateConfig(String templateIdOrApiName)

Parameters

  • templateIdOrApiName:

    Type: String

    The template ID or developer name to retrieve the template configuration for.

Return Value

Type: Map<String,Object>

A map of template configuration JSON attribute names and the object values. For attribute details, see TemplateConfigurationRepresentation.

Example

Map<String, Object> templateVariables = (Map<String, Object>) Wave.Templates.getTemplateConfig(templateId).get('variables');

Here, templateId is a placeholder value.

getTemplates(options)

Get a filtered collection of CRM Analytics templates using search options.

Signature

public static Map<String,Object> getTemplates(Wave.TemplatesSearchOptions options)

Parameters

Return Value

Type: Map<String,Object>

A map of template names and the template object values. For template collection details, see TemplateCollectionRepresentation.

Example

Map<String,Object> templatesMap = Wave.Templates.getTemplates(new Wave.TemplatesSearchOptions());

getTemplates()

Gets all CRM Analytics templates.

Signature

public static Map<String,Object> getTemplates()

Return Value

Type: Map<String,Object>

A map of template names and the template object values. For template collection details, see TemplateCollectionRepresentation.

Example

Map<String,Object> templatesMap = Wave.Templates.getTemplates();