I’m working on one LWC and facing issue while passing parameters to an apex method which I am calling imperatively on selection of a record in datatable. I’m able to get selected recordid in JS function and call js function but I always get error when parameter is passed. Imperative calling seems to be working fine when no param is passed. Code posted below:
Import:
import executeAction from '@salesforce/apex/DSE_SetAccountAdmin_CtrlX.executeAction';
buttonClickHandler:
buttonClicked(event) { executeAction(labelToActionMap.get(event.target.label), this.selectedContact.Id) .then(result => { console.log('TCL: dseContactManagementForSelectedAccountLwc -> buttonClicked -> result', result) }) .catch(error => { console.log('TCL: dseContactManagementForSelectedAccountLwc -> buttonClicked -> error', error) }); }
Apex method declaration:
@AuraEnabled
public static Boolean executeAction(String actionName, String selectedContactId){I keep getting below error in console.
I believe I’m missing some syntax here. Do I need to pass params as a map object as shown in error?
Answer
Yes, it’s supposed to be an object:
executeAction({ actionName: labelToActionMap.get(event.target.label),
selectedContactId: this.selectedContact.Id })
The object key values should match the Apex parameter names.
Attribution
Source : Link , Question Author : Ashish Sharma , Answer Author : sfdcfox