0

Actually, I am working on lightning web components and creating a custom application on Salesforce 1 app for mobile. I am creating custom front end on LWC and custom back-end. On first screen, I have a custom record view and when I click on edit button, an edit form opens with auto-populated input fields in which we can edit/change value of any field. After changing any field's value and clicking on save, it updates the value in Database as well as on my record view screen.

The issue is when I open the edit form and change any value and instead of save, I cancel it. Then I again go on edit form the auto filled fields show those values that I have changed, not those values that are saved in Database (I am retrieving values from database through @wire). The issue I noticed is that 2nd time the app loads the edit form from LDS cache not from Database. Is there any solution of this problem? When I reopen the edit form, so it loads data from Database not from cache.

1 Answer 1

0

I have faced similar kind of issue in LWC like even data is updated in the database, the component would show the data from the cache. To overcome this I called refreshapex method after saving the record.

In your case, you can call the refreshapex when cancel button is clicked.

See the example.

// opportunitiesOverAmount.js
import { LightningElement, api, wire } from 'lwc';
import { refreshApex } from '@salesforce/apex';
import getOpptyOverAmount from '@salesforce/apex/OpptiesOverAmountApex.getOpptyOverAmount';
import updateOpptyStage from '@salesforce/apex/OpptiesOverAmountApex.updateOpptyStage';

export default class OpportunitiesOverAmount extends LightningElement {
    @api amount = 500000;

    @wire(getOpptyOverAmount, { amount: '$amount' })
    opptiesOverAmount;

    handleClick(e) {
        updateOpptyStage({
            amount: this.amount,
            stage: 'Closed Won'
        })
        .then(() => {
            return refreshApex(this.opptiesOverAmount);
        })
        .catch((error) => {
            this.message = 'Error received: code' + error.errorCode + ', ' +
                'message ' + error.body.message;
        });
    }
}

If you are using the imperative method:

import { LightningElement, api, wire } from 'lwc';
import { refreshApex } from '@salesforce/apex';
import getActivityHistory from '@salesforce/apex/GalleryApexController.getActivityHistory';

export default class GalleryApexMaster extends LightningElement {
    @api recordId;
    wiredActivities;

    @wire(getActivityHistory, { accountId: '$recordId', max: '500' })
    wiredGetActivityHistory(value) {
        // Hold on to the provisioned value so we can refresh it later.
        this.wiredActivities = value; // track the provisioned value
        const { data, error } = value; // destructure the provisioned value
        if (data) { ... }
        else if (error) { ... }
        ...
    }

    handleLogACall() {
        // Use the value to refresh wiredGetActivityHistory().
        return refreshApex(this.wiredActivities);
    }
}

Here you can find more info on refresh apex.

2
  • Thank you for your reply but this is not working i have implement this. The salesforce 1 app still loads the edit screen from LDS cache instead of retrieving data from Database. Actually, salesforce is responding perfectly on Desktop but this issue is already and still there in Salesforce Mobile App Commented Dec 20, 2019 at 9:47
  • @ahmadhassan Did you by any chance resolved this issue. I am facing the same problem. My component loads perfectly on the first go but when I do the same thing on a different record my component shows values from different record altogether. This happens only on Salesforce mobile app.
    – Badduboy
    Commented Aug 19, 2021 at 15:50

You must log in to answer this question.

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