I have a simple button handle click function which calls the apex method and pass the params. However, if I pass the @track variable as param, then apex method is not getting called. If I pass the static value it is working fine. not sure what I am missing.
Javascript Method: (Working)
handleClick(){
window.console.log('inside button click: '+this.selectedOptionsList);
const fLst = 'type';
window.console.log('fLst: '+fLst);
fetchPermissions({ sObjectName: 'Account', fieldList: fLst})
.then(result => {
//this.contacts = result;
window.console.log(JSON.stringify(result));
})
.catch(error => {
this.error = error;
});
}
Console Log: (Working)
Javascript Method: (Not Working)
handleClick(){
window.console.log('inside button click: '+this.selectedOptionsList);
const fLst = 'type';
window.console.log('fLst: '+fLst);
fetchPermissions({ sObjectName: 'Account', fieldList: this.selectedOptionsList})
.then(result => {
//this.contacts = result;
window.console.log(JSON.stringify(result));
})
.catch(error => {
this.error = error;
});
}
Dual-list box onchange Event:
handleChange(event) {
// Get the list of the "value" attribute on all the selected options
this.selectedOptionsList = event.detail.value;
window.console.log(`Options selected: ${this.selectedOptionsList}`);
}
Simple APEX method:
@AuraEnabled(cacheable=true)
public static String getPermissions(String sObjectName, String fieldList){
return fieldList;
}
If you see in the log, both @track variable value and cont variable value are the same. However, I don't get the result if I pass the @track variable as you see in the log.
Best Answer
I found the issue, for some reason track variable value is set as an object instead of a string, that is the reason apex method is not accepting it.
I just stringify the object and sending it to the apex. It is working fine.