0

I have a proxy object(this.fieldValue) that looks like the following: Proxy {0: '2. Service - Cancellations', 1: '2. Service - Claim APP - Technical Issues'}

I would need to pass the dict inside the proxy {0: '2. Service - Cancellations', 1: '2. Service - Claim APP - Technical Issues'} to an APEX function that is waiting for a map but I am having a lots of trouble doing it

I found on some pages that I can deproxified the data using this: const val = {...this.fieldValue};

But still when I pass it to the APex function the data is NUll

here is my code:

handleSave(event){
    const val = {...this.fieldValue};
    console.log(val);
    
    console.log("save launched")
    console.log(typeof val);
     
    saveTags(
        val
        
    ).then(result =>{
        console.log("Saved") 
        this.message = 'Tag Saved';
    }).catch(error =>{
        console.log('Tag issue Saved');
        this.message = 'Error while creating tags'
    })
    console.log("Done") 
    this.toDisplay = !this.toDisplay
    this.cancelSave = !this.cancelSave
}

and APEX code:

@AuraEnabled
    public static void saveTags(map<integer, string> Tag){
        System.debug('Launched');
        System.debug(Tag); 
        
    }

could you give me a hand please ?

1 Answer 1

1

Your problem is that you didn't put the value into the proper parameter name. Parameters are passed in as an object with the properties matching the case-sensitive names of the parameter, as in:

saveTags({ Tag: this.fieldValue })

Note that it is not necessary to use {...this.fieldValue}; the Proxy is just a side effect of Locker Service, and is transparent to the code that's working with the data.

6
  • It still returns me a NULL in my System.debug(Tag); ;(((
    – Ben2pop
    Apr 13, 2022 at 11:32
  • @Ben2pop Hmm, are you sure it's an Object, and not actually an Array? Maybe it's being parsed as an Array? Does it have a length property, which would make it Array-like?
    – sfdcfox
    Apr 13, 2022 at 19:55
  • I think there is something I do not get with Imperative Method in apex .. what I would like it to pass to my method the id of the object to update and a list of fields to update to true .. so I would like something {id : [field1,field2,field3]} but it is always NULL. I even try simple {id: ['string1','string2','string3']} and my apex Map<String, String> Tag and it is not working. Attempt to de-reference a null object
    – Ben2pop
    Apr 14, 2022 at 6:06
  • @Ben2pop That's definitely a problem; {id: ['string1','string2','string3']} would match the Apex method signature: saveTags(String[] id).
    – sfdcfox
    Apr 14, 2022 at 13:19
  • how String[] is different thant List<String>. ? thx you ?
    – Ben2pop
    Apr 14, 2022 at 15:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .