Newer Version Available

This content describes an older version of this product. View Latest

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.

1@AuraEnabled(cacheable=true)
2public static void List<String> getTemplateNames() {
3  Map<String, Object> o = Wave.Templates.getTemplates(new Wave.TemplatesSearchOptions());
4  List<Object> templates = (List<Object>) o.get('templates');
5  List<String> names = new List<String>();
6  for (Object templateObj : templates) {
7    names.add((String) ((Map<String, Object>) templateObj.get('name'));
8  }
9  return names;
10}

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

For example, in the lwc.js file:

1import getTemplates from '@salesforce/apex/Wave.Templates.getTemplates';
2export default class Templates extends LightningElement {
3  @wire(getTemplates, {
4    // specifying 'options' is optional
5    options: {
6      // values in TemplatesSearchOptions go here; all optional
7      type: 'app'
8    }
9  })
10  onTemplates({ data, error }) {
11    if (data) {
12      console.log('template names=' + data.templates.map(l => l.name).join(', '));
13    }
14  }
15}

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

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

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

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

getTemplates(options)

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

Signature

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

Parameters

options
Type: Wave.TemplatesSearchOptions
The search options to use for filtering the template collection.

Return Value

Type: Map<String,Object>

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

Example

1Map<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

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