Skip to content

refreshApex on wired adapter in ERROR-State (property .error supplied) not updating .data or .error on subsequent request #3990

Open
@t0ng4

Description

@t0ng4

Description

When calling refreshApex on an wired adapter that is in an error state (.error property is != undefined) any refreshed/updated response from Apex Call is NOT being assigned to the .error property of the wired property. The .error property keeps the state of the initial error.

This will cause problem when a initially failed apex call is supposed to be repeated (e.g. a external system was temporarily not available/timed out and the user wants to re-try the request).

Steps to Reproduce

  1. Create LWC that wires an @AuraEnabled Apex Controller method that intentionally throws an AuraHandledException right away with current DateTime.now() as Error message:

Apex


public with sharing class ErrorSimulatorController {
    @AuraEnabled(cacheable=true)
    public static String simulateError() {
           AuraHandledException exc = new AuraHandledException(
                'Simple error message: ' + String.valueOf(DateTime.now())
            );
            throw exc;
    }
}


JS

import { LightningElement, wire } from 'lwc';
import { refreshApex } from '@salesforce/apex';
import simulateError from '@salesforce/apex/ErrorSimulatorController.simulateError';

 @wire(simulateError)
    wiredResult; 

handleRefresh() {
     refreshApex(this.wiredResult)
}

get wired() {
    return JSON.stringify(this.wiredResult);
}

  1. Add {wired} output and a button in template that onclick calls handler handleRefresh
    HTML
<template>
     <div>
           {wired}
           <div onclick={handleRefresh}></div>
      </div>
</template>
  1. Click button to refresh wiredAdapter and make call to Apex.

Expected Results

The initial request to simulateError via wiredResult on component creation shows the first timestamp. When refreshing the wiredResult via refreshApex I would expect that the updated error-response from simulateError is provisioned to the wiredResult.error property, indicated by an updated Timestamp showing via {wired} in template.

Actual Results

In chrome dev console I can see the request to Apex is being made and having an updated timestamp in the response. However, the wiredResult.error property keeps the response of the initial request when component was created.

Browsers Affected

Tested with Chrome 121.0.6167.139

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    External: Other SalesforceCategorizes issue or PR as related to Salesforce related features.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions