Use the Templates class to retrieve a collection of CRM Analytics templates, describe a single template and template configuration.
The CRM Analytics Wave.Templates class provides access from Apex to CRM Analytics templates. The methods are annotated with @AuraEnabled for use in Lightning Web Components (LWC).
Retrieves a collection of templates using search options.
Apex Class Example
1public with sharing class TemplatesController{2 public TemplatesController(){3}45 @AuraEnabled(cachable=true)6 public static List<String, Object>getTemplateNames(){7 // This has filterGroup, type, and options; all fields are optional/nullable8 Wave.TemplatesSearchOptions options = new Wave.TemplatesSearchOptions();9 options.type = 'app';10 options.filterGroup = 'small';11 options.options = 'ViewOnly';1213 // Pass null to get the default search options or leave it off completely to return14 // a collection with no search options15 Map<String, Object>templates = Wave.Templates.getTemplates(options);1617 // templates is the JSON response as an Apex Map (from JSON.deserializedUntyped), which18 // you can pull fields from19 List<Object>templateList = (List<Object>)templates.get('templates');20 List<String>names = new List<String>();21 for(Object templateObj : templateList){22 names.add((String)((Map<String, Object>)templateObj).get('name'));23}24 return names;25}26}
LWC Example
1import {LightningElement, wire} from "lwc";2import getTemplates from "@salesforce/apex/Wave.Templates.getTemplates";34export default class Templates extends LightningElement {5 results;67 @wire(getTemplates, {8 options: {9 // All are optional10 type = 'app'11 }12 })1314 // can also use these15 // @wire(getTemplates, { options: {} })16 // @wire(getTemplates, {})17 // @wire(getTemplates)18 // @wire(getTemplates, { options: {'$options'} }) // with a binding19 onTemplates({ data, error }) {20 if (error) {21 this.results = "Error:\n" + JSON.stringify(error, undefined, 2);22 } else if (data) {23 // data is the TemplateCollectionRepresentation JSON object24 this.results = 'Template names: ' + data.templates.map(l => ${l.name}).join(', ');25 } else {26 this.results = "No data";27 }28 }29}
Retrieves a template configuration by ID or the API name.
Apex Class Example
1public with sharing class TemplateController {2 public TemplateController() {3 }45 @AuraEnabled(cacheable=true)6 public static Map<String, Object> getTemplate(String idOrName) {7 Map<String, Object> template = Wave.Templates.getTemplate(idOrName);8 return template;9 }10}
LWC Example
1import {LightningElement, wire} from "lwc";2import getTemplate from "@salesforce/apex/Wave.Templates.getTemplate";34export default class Lens extends LightningElement {5 templateIdOrApiName; // set this to the ID or name you want to retrieve67 results;89 @wire(getTemplate, {10 templateIdOrApiName: '$templateIdOrApiName'11 })12 onTemplate({data, error}) {13 if (error) {14 this.results = "Error:\n" + JSON.stringify(error, undefined, 2);15 } else if (data) {16 // data is the TemplateRepresentation JSON object17 this.results = 'Template: ${data.name} ${data.id}';18 } else {19 this.results = "No data";20 }21 }22}