call apex method in lwc code example
Example: call a method imperatively in lwc
import { LightningElement,wire,track } from 'lwc';
import getAllActiveAccounts from '@salesforce/apex/AccountController.getAllActiveAccounts';
export default class WireMethodDemo extends LightningElement {
@track accountsList;
@track showAccounts;
onShowClick(){
getAllActiveAccounts()
.then(result => {
this.accountsList = result;
this.showAccounts = true;
})
.catch(error => {
console.log('Error Occured:- '+error.body.message);
});
}
onHideClick(){
this.showAccounts = false;
}
}