0

I'm building a lightning component using the new Lightning Web Component framework, the component retrieves information from a custom setting with three checkboxes, once the user changes the values of those fields, and hits Save, the record is updated. If I navigate to the Home tab, and then I come back to the custom tab that contains the component, it shows the previous value. It has to be something with the cache, any ideas?

NOTE: The getMyValues method returns something back to the component, only if I set (cacheable=true)

.html

<form>
    <lightning-checkbox-group name="Checkbox Group"
    label="Checkbox Group"
    options={options}
    value={value}
    onchange={handleChange} class="slds-m-around_medium"> 
    </lightning-checkbox-group>
</form>
<lightning-button label="Save" title="Save" onclick={handleSaveClick} />

.js

import { LightningElement, track, wire } from 'lwc';

import getMyValues from '@salesforce/apex/MyController.getMyValues';
import setMyValues from '@salesforce/apex/MyController.setMyValues';

    export default class CheckboxGroupBasic extends LightningElement {

        @track value = [];

        @wire (getMyValues)
        wiredMyValues({error, data}){
            let deserializedData;
            if (data){
                deserializedData = JSON.parse(data);
                if (deserializedData.Value1)
                    this.value.push('value-1')
                if (deserializedData.Value2)
                    this.value.push('value-2')
            }
        }

        handleSaveClick() {
            // DML action here... // WORKS FINE
        }
    }

apex controller

@AuraEnabled(cacheable=true)
public static String getMyValues(){
    ConfigOptions__c config =  ConfigOptions__c.getValues('My Config');
    return JSON.serialize(config);
}
  • you will need to share a minimal reproduceable code sample for better assistance – glls Apr 3 at 15:07
  • As glls mentioned it is hard to say for sure with the limited information, but this may help you. – Aayush K Apr 3 at 15:13

Your Answer

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

Browse other questions tagged or ask your own question.