salesforce - working with records
This setup uses a controller that contains the following code, please note that this code is available in /default/classes/bearController.cls
'
Notice how different the import path is :-
import getAllBears from '@salesforce/apex/BearController.getAllBears';
loadBears() { getAllBears() .then(result => { this.bears = result; }) .catch(error => { this.error = error; }); }
The funny thing about this code is, it returns mostly string which contains SOQL query. Still not really sure how it works under the hood.
This is imperative query.. However, you can greatly simplify the code using @wire as shown below:-
import { LightningElement, wire } from 'lwc'; import ursusResources from '@salesforce/resourceUrl/ursus_park'; /** BearController.getAllBears() Apex method */ import getAllBears from '@salesforce/apex/BearController.getAllBears'; export default class BearList extends LightningElement { @wire(getAllBears) bears; appResources = { bearSilhouette:
ursusResources +'/img/standing-bear-silhouette.png', }; }
Comments