Skip to main content
Became Hot Network Question
added 260 characters in body
Source Link
molinet
  • 935
  • 5
  • 22
  • 49

I have a custom lwc that works with refresh apex. I want a method to be refreshed from another function

js:

import {refreshApex} from '@salesforce/apex';
import initData from '@salesforce/apex/myClass.initData';

export default class Tm_GDPRInfoSignatureLWC LightningElement {

    wiredGDPRresult;
    @track myData;

    @wire(initData , {recordId : '$recordID'}) wiredInitData(result) {
        this.wiredGDPRresult = result;
        //data retrieved
        if(result.data) {
            console.log('entered');
            this.myData = result.data;
            console.log('finished');
        }
        //error
        else if(result.error){
            console.log(JSON.stringify(result.error));
        }
    }

    refreshData(){
        return refreshApex(this.wiredGDPRresult);
    }
}

And it's working find when initializing the lwc but whenever I call refreshData it's doing nothing (not even displaying console.logs())

Is there something I'm setting wrong or do I need to call refreshApex in a different way?

EDIT

I'm calling my function whenever I receive a custom event from another lwc. And it's receiving that event but refreshApex doesn't do anything

connectedCallback(){
    registerListener('refreshData', this.refreshData, this);
}

I have a custom lwc that works with refresh apex. I want a method to be refreshed from another function

js:

import {refreshApex} from '@salesforce/apex';
import initData from '@salesforce/apex/myClass.initData';

export default class Tm_GDPRInfoSignatureLWC LightningElement {

    wiredGDPRresult;
    @track myData;

    @wire(initData , {recordId : '$recordID'}) wiredInitData(result) {
        this.wiredGDPRresult = result;
        //data retrieved
        if(result.data) {
            console.log('entered');
            this.myData = result.data;
            console.log('finished');
        }
        //error
        else if(result.error){
            console.log(JSON.stringify(result.error));
        }
    }

    refreshData(){
        return refreshApex(this.wiredGDPRresult);
    }
}

And it's working find when initializing the lwc but whenever I call refreshData it's doing nothing (not even displaying console.logs())

Is there something I'm setting wrong or do I need to call refreshApex in a different way?

I have a custom lwc that works with refresh apex. I want a method to be refreshed from another function

js:

import {refreshApex} from '@salesforce/apex';
import initData from '@salesforce/apex/myClass.initData';

export default class Tm_GDPRInfoSignatureLWC LightningElement {

    wiredGDPRresult;
    @track myData;

    @wire(initData , {recordId : '$recordID'}) wiredInitData(result) {
        this.wiredGDPRresult = result;
        //data retrieved
        if(result.data) {
            console.log('entered');
            this.myData = result.data;
            console.log('finished');
        }
        //error
        else if(result.error){
            console.log(JSON.stringify(result.error));
        }
    }

    refreshData(){
        return refreshApex(this.wiredGDPRresult);
    }
}

And it's working find when initializing the lwc but whenever I call refreshData it's doing nothing (not even displaying console.logs())

Is there something I'm setting wrong or do I need to call refreshApex in a different way?

EDIT

I'm calling my function whenever I receive a custom event from another lwc. And it's receiving that event but refreshApex doesn't do anything

connectedCallback(){
    registerListener('refreshData', this.refreshData, this);
}
deleted 1 character in body
Source Link
molinet
  • 935
  • 5
  • 22
  • 49

I have a custom lwc that works with refresh apex. I want a method to be refreshed from another function

js:

import {refreshApex} from '@salesforce/apex';
import initData from '@salesforce/apex/myClass.initData';

export default class Tm_GDPRInfoSignatureLWC LightningElement {

    wiredGDPRresult;
    @track myData;

    @wire(checkGDPRinitData , {recordId : '$recordID'}) imperativeWirewiredInitData(result) {
        this.wiredGDPRresult = result;
        //data retrieved
        if(result.data) {
            console.log('entered');
            this.myData = result.data;
            console.log('finished');
        }
        //error
        else if(result.error){
            console.log(JSON.stringify(result.error));
        }
    }

    refreshData(){
        return refreshApex(this.wiredGDPRresult);
    }
}

And it's working find when initializing the lwc but whenever I call refreshData it's doing nothing (not even displaying console.logs())

Is there something I'm setting wrong or do I need to call refreshApex in a different way?

I have a custom lwc that works with refresh apex. I want a method to be refreshed from another function

js:

import {refreshApex} from '@salesforce/apex';
import initData from '@salesforce/apex/myClass.initData';

export default class Tm_GDPRInfoSignatureLWC LightningElement {

    wiredGDPRresult;
    @track myData;

    @wire(checkGDPR, {recordId : '$recordID'}) imperativeWire(result) {
        this.wiredGDPRresult = result;
        //data retrieved
        if(result.data) {
            console.log('entered');
            this.myData = result.data;
            console.log('finished');
        }
        //error
        else if(result.error){
            console.log(JSON.stringify(result.error));
        }
    }

    refreshData(){
        return refreshApex(this.wiredGDPRresult);
    }
}

And it's working find when initializing the lwc but whenever I call refreshData it's doing nothing (not even displaying console.logs())

Is there something I'm setting wrong or do I need to call refreshApex in a different way?

I have a custom lwc that works with refresh apex. I want a method to be refreshed from another function

js:

import {refreshApex} from '@salesforce/apex';
import initData from '@salesforce/apex/myClass.initData';

export default class Tm_GDPRInfoSignatureLWC LightningElement {

    wiredGDPRresult;
    @track myData;

    @wire(initData , {recordId : '$recordID'}) wiredInitData(result) {
        this.wiredGDPRresult = result;
        //data retrieved
        if(result.data) {
            console.log('entered');
            this.myData = result.data;
            console.log('finished');
        }
        //error
        else if(result.error){
            console.log(JSON.stringify(result.error));
        }
    }

    refreshData(){
        return refreshApex(this.wiredGDPRresult);
    }
}

And it's working find when initializing the lwc but whenever I call refreshData it's doing nothing (not even displaying console.logs())

Is there something I'm setting wrong or do I need to call refreshApex in a different way?

Source Link
molinet
  • 935
  • 5
  • 22
  • 49

refreshApex in lwc doesn't seem to work

I have a custom lwc that works with refresh apex. I want a method to be refreshed from another function

js:

import {refreshApex} from '@salesforce/apex';
import initData from '@salesforce/apex/myClass.initData';

export default class Tm_GDPRInfoSignatureLWC LightningElement {

    wiredGDPRresult;
    @track myData;

    @wire(checkGDPR, {recordId : '$recordID'}) imperativeWire(result) {
        this.wiredGDPRresult = result;
        //data retrieved
        if(result.data) {
            console.log('entered');
            this.myData = result.data;
            console.log('finished');
        }
        //error
        else if(result.error){
            console.log(JSON.stringify(result.error));
        }
    }

    refreshData(){
        return refreshApex(this.wiredGDPRresult);
    }
}

And it's working find when initializing the lwc but whenever I call refreshData it's doing nothing (not even displaying console.logs())

Is there something I'm setting wrong or do I need to call refreshApex in a different way?