1

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)

enter image description here

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;
            });

    }

Console Log: (Not Working) enter image description here

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.

  • Show us how you declare this.selectedOptionsList and any code that can alter it. – zaitsman Jul 24 '19 at 23:41
  • @zaitsman, added the code where I am setting the value from onchange event from dual-list component. – Ajay Jul 24 '19 at 23:52
  • So what is logged if you do console.log(event.detail.value);? – zaitsman Jul 24 '19 at 23:53
  • @zaitsman, expected value 'type' is printing in the log. I added the log file too. – Ajay Jul 24 '19 at 23:55
  • sorry, then i literally don't get what is not working? your log shows inside button click: type in response to window.console.log('inside button click: '+this.selectedOptionsList);. What is not working? – zaitsman Jul 24 '19 at 23:57
2

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.

| improve this answer | |
  • when using decorator annotated properties they will be wrapped in salesforce observable membrane (which is responsible for notifying about changes so the rererendering is happening) - thats the reason why they are an object – Renji-xD Jul 25 '19 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.