Retrieves a collection of lenses using search options.
Apex Class Example
1public with sharing class LensController {2 public LensController() {3 }45 @AuraEnabled(cachable=true)6 public static Map<String, Object> getLenses() {7 // This has all fields available, plus filterGroup; all fields are optional/nullable8 Wave.LensesSearchOptions options = new Wave.LensesSearchOptions();9 options.q = 'widget';10 options.filterGroup = 'supplemental';11 options.scope = 'CreatedByMe';12 options.page = null;13 options.sortParam = 'Name';1415 // Pass null to get the default search options or leave it off completely to return16 // a collection with no search options17 Map<String, Object> lensesJson = Wave.Lenses.getLenses(options);1819 // lensesJson is the JSON response as an Apex Map (from JSON.deserializedUntyped), which20 // you can pull fields from21 return lensesJson;22 }23}
LWC Example
1import {LightningElement, wire} from "lwc";2import getLenses from "@salesforce/apex/Wave.Lenses.getLenses";34export default class Lenses extends LightningElement {5 results;67 @wire(getLenses, {8 options: {9 // All are optional10 filterGroup = "Supplemental",11 sortParam = "Name"12 }13 })14 // can also use these15 // @wire(getLenses, { options: {} })16 // @wire(getLenses, {})17 // @wire(getLenses)18 // @wire(getLenses, { options: {'$options'} }) // with a binding19 onLenses({data, error}) {20 if (error) {21 this.results = "Error:\n" + JSON.stringify(error, undefined, 2);22 } else if (data) {23 // data is the LensCollectionRepresentation JSON object24 this.results = "Lenses: " + data.lenses.map(l => `${l.name} {$l.id}`).join(", ");25 } else {26 this.results = "No data";27 }28 }29}
Retrieves a lens by ID or the API name and a filterGroup parameter.
Apex Class Example
1public with sharing class LensController {2 public LensController() {3 }45 @AuraEnabled(cacheable=true)6 public static Map<String, Object> getLens(String idOrName) {7 Map<String, Object> lens = Wave.Lenses.getLens(idOrName);8 return lens;9 }10}
LWC Example
1import {LightningElement, wire} from "lwc";2import getLenses from "@salesforce/apex/Wave.Lenses.getLens";34export default class Lens extends LightningElement {5 lensIdOrApiName; // set this to the ID or name you want to retrieve67 results;89 @wire(getLens, {10 lensIdOrApiName: '$lensIdOrApiName'11 })12 onLens({data, error}) {13 if (error) {14 this.results = "Error:\n" + JSON.stringify(error, undefined, 2);15 } else if (data) {16 // data is the LensRepresentation JSON object17 this.results = `Lens: ${data.name} ${data.id})`;18 } else {19 this.results = "No data";20 }21 }22}