How to refresh wired service getRecord manually?LWC Force Refresh Wire getRecordForce update lightning-record-view-formWhen do @wire methods run (LWC)?LWC : passing parameter to getrecordLWC Force Refresh Wire getRecordHow to use wired function?How to avoid error Cannot read property of undefined using two LWC Wired propertiesLWC: wire and getRecord, get field valuesgetRecord in connectCallbackHow to get an LWC component on a record page to refresh when that page is updatedLWC renderedCallback not retrieving a wired recordimperative apex method not called from wire
Cherem ceremony: candles?
Am I overreacting or seeing things where they don't exist?
Did the computer mouse always output relative x/y and not absolute?
What are examples of (collections of) papers which "close" a field?
Possible bug in NMaximize function?
SQL Server: Multiple Availability Groups, one cluster, how do I keep the primary cluster node as primary?
How to protect assets from being passed to a beneficiary in a will when they are likely to die soon also
Is it possible for a moon to have a higher surface gravity than the planet it is attached to?
Can a VASIMR Plasma engine be used for vertical takeoff?
Controlling a robot blindfolded on a 9x9 grid
How much do I need to invest monthly to accumulate a given amount?
What would happen if the Queen died immediately before a general election?
Mirrors on both bars
Is Absorb Elements cast before or after a save? Is it cast before or after damage?
Can we violate law of physics in any other planet?
Schemes/ Mechanisms that could provide one time decryption?
What made the Tusken Raiders unable / unwilling to shoot down Luke's Landspeeder?
Why aren't there attempts to evolve classical musical instruments so that they're easier to play?
Generate array of integers that sum to zero
How do I use an .img.xz file or get an .img file from it?
What is the meaning of "wiped my face with a planet"?
Do attacks that give the Grappled condition work against creatures more than 1 size larger?
"Don't invest now because the market is high"
Temporary queue to prevent duplication
How to refresh wired service getRecord manually?
LWC Force Refresh Wire getRecordForce update lightning-record-view-formWhen do @wire methods run (LWC)?LWC : passing parameter to getrecordLWC Force Refresh Wire getRecordHow to use wired function?How to avoid error Cannot read property of undefined using two LWC Wired propertiesLWC: wire and getRecord, get field valuesgetRecord in connectCallbackHow to get an LWC component on a record page to refresh when that page is updatedLWC renderedCallback not retrieving a wired recordimperative apex method not called from wire
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
Please note that this is not duplicate of LWC Force Refresh Wire getRecord - this question and answer specifically speaks about changes in front-end/UI and capturing that in front-end BUT LDS cannot listen to database changes to record and so we need to manually refresh LDS record cache.
Question:
According to documentation of refreshApex, if we know that record has been updated in database, we can invoke refreshApex
to re-invoke and refresh the cached response of Apex method response.
But for wired service getRecord, there is no such method to manually refresh the cache and it refreshes the cache only after 30 seconds from last fetching the record ( - if invoked within or after 30 seconds). If I know that the record has been updated in the database through some backend transaction (like workflow), how can we manually refresh cache of getRecord
?
lightning lightning-web-components lwc-wire-adapter
add a comment
|
Please note that this is not duplicate of LWC Force Refresh Wire getRecord - this question and answer specifically speaks about changes in front-end/UI and capturing that in front-end BUT LDS cannot listen to database changes to record and so we need to manually refresh LDS record cache.
Question:
According to documentation of refreshApex, if we know that record has been updated in database, we can invoke refreshApex
to re-invoke and refresh the cached response of Apex method response.
But for wired service getRecord, there is no such method to manually refresh the cache and it refreshes the cache only after 30 seconds from last fetching the record ( - if invoked within or after 30 seconds). If I know that the record has been updated in the database through some backend transaction (like workflow), how can we manually refresh cache of getRecord
?
lightning lightning-web-components lwc-wire-adapter
add a comment
|
Please note that this is not duplicate of LWC Force Refresh Wire getRecord - this question and answer specifically speaks about changes in front-end/UI and capturing that in front-end BUT LDS cannot listen to database changes to record and so we need to manually refresh LDS record cache.
Question:
According to documentation of refreshApex, if we know that record has been updated in database, we can invoke refreshApex
to re-invoke and refresh the cached response of Apex method response.
But for wired service getRecord, there is no such method to manually refresh the cache and it refreshes the cache only after 30 seconds from last fetching the record ( - if invoked within or after 30 seconds). If I know that the record has been updated in the database through some backend transaction (like workflow), how can we manually refresh cache of getRecord
?
lightning lightning-web-components lwc-wire-adapter
Please note that this is not duplicate of LWC Force Refresh Wire getRecord - this question and answer specifically speaks about changes in front-end/UI and capturing that in front-end BUT LDS cannot listen to database changes to record and so we need to manually refresh LDS record cache.
Question:
According to documentation of refreshApex, if we know that record has been updated in database, we can invoke refreshApex
to re-invoke and refresh the cached response of Apex method response.
But for wired service getRecord, there is no such method to manually refresh the cache and it refreshes the cache only after 30 seconds from last fetching the record ( - if invoked within or after 30 seconds). If I know that the record has been updated in the database through some backend transaction (like workflow), how can we manually refresh cache of getRecord
?
lightning lightning-web-components lwc-wire-adapter
lightning lightning-web-components lwc-wire-adapter
asked Sep 26 at 8:34
salesforce-sassalesforce-sas
14.3k2 gold badges5 silver badges30 bronze badges
14.3k2 gold badges5 silver badges30 bronze badges
add a comment
|
add a comment
|
2 Answers
2
active
oldest
votes
To make refreshApex clear the client-side cache it is necessary to capture and store the entire result from the getRecord wire. In this case you cannot define your handler to accept an anonymous object with data and error properties.
You need to do something like the following. First add a private property to hold the result:
_getRecordResponse;
Then update the handling of the getRecord wire response from something like:
@wire(getRecord, ...)
receiveRecord(error, data)
...
to:
@wire(getRecord, ...)
receiveRecord(response)
this._getRecordResponse = response;
let error = response && response.error;
let data = response && response.data;
...
Now that you have the _getRecordResponse, you can force the record to be reloaded by calling:
refreshApex(this._getRecordResponse);
Worth also noting you might be able to listen for changes in the backend using the Emp service - basically using streaming API and a change event.
– Phil W
Sep 26 at 9:27
Thanks Phil!, when I tried this implementation before, I was not getting log and so thought its not refreshing. I answered for that part below
– salesforce-sas
Sep 26 at 10:04
add a comment
|
Extending answer from @Phil W,
For below Sample LWC Js:
@api recordId = '00128000009j45tAAA';
@track wiredAccount;
fields = [ACCOUNT_NAME_FIELD, ACCOUNT_DESCRIPTION_FIELD];
@wire(getRecord, recordId: '$recordId', fields: '$fields' )
fetchAcc(response)
console.log('Account => ', JSON.stringify(response));
this.wiredAccount = response;
refreshWire()
refreshApex(this.wiredAccount);
Although we invoke refreshWire
, the wired method fetchAcc
will be invoked ONLY if new record and UI record in this.wiredAccount
are not same and consecutively see the console log. If the new record is same as UI record this.wiredAccount
, the method fetchAcc
will not be invoked (even after 30 seconds) and we will not see any console log. Finally, refreshApex should have been named refreshWire as it not just updates apex method response but also wired service response.
refreshApex is, I would presume, called refreshApex because both imperative and wired calls are fundamentally both just calling a (cacheable) AuraEnabled Apex method. The difference with a wired service is that there is client-side logic for handling caching (and for detecting changes to wired "reactive" parameters for re-invocation).
– Phil W
Sep 26 at 10:25
@PhilW So, you meangetRecord
is internally apex method in lightning namespace ?
– salesforce-sas
Sep 26 at 10:31
Yeah, I would think so. It seems like Salesforce is generally pretty good at using its own plumbing to implement stuff. Obviously I can't guarantee this since I've not seen the code, but it makes sense to do it this way.
– Phil W
Sep 26 at 10:49
crap.. this is good.. I was doing eval('$A.force.refreshView`)
– Pranay Jaiswal
Sep 26 at 15:52
add a comment
|
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "459"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f279516%2fhow-to-refresh-wired-service-getrecord-manually%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
To make refreshApex clear the client-side cache it is necessary to capture and store the entire result from the getRecord wire. In this case you cannot define your handler to accept an anonymous object with data and error properties.
You need to do something like the following. First add a private property to hold the result:
_getRecordResponse;
Then update the handling of the getRecord wire response from something like:
@wire(getRecord, ...)
receiveRecord(error, data)
...
to:
@wire(getRecord, ...)
receiveRecord(response)
this._getRecordResponse = response;
let error = response && response.error;
let data = response && response.data;
...
Now that you have the _getRecordResponse, you can force the record to be reloaded by calling:
refreshApex(this._getRecordResponse);
Worth also noting you might be able to listen for changes in the backend using the Emp service - basically using streaming API and a change event.
– Phil W
Sep 26 at 9:27
Thanks Phil!, when I tried this implementation before, I was not getting log and so thought its not refreshing. I answered for that part below
– salesforce-sas
Sep 26 at 10:04
add a comment
|
To make refreshApex clear the client-side cache it is necessary to capture and store the entire result from the getRecord wire. In this case you cannot define your handler to accept an anonymous object with data and error properties.
You need to do something like the following. First add a private property to hold the result:
_getRecordResponse;
Then update the handling of the getRecord wire response from something like:
@wire(getRecord, ...)
receiveRecord(error, data)
...
to:
@wire(getRecord, ...)
receiveRecord(response)
this._getRecordResponse = response;
let error = response && response.error;
let data = response && response.data;
...
Now that you have the _getRecordResponse, you can force the record to be reloaded by calling:
refreshApex(this._getRecordResponse);
Worth also noting you might be able to listen for changes in the backend using the Emp service - basically using streaming API and a change event.
– Phil W
Sep 26 at 9:27
Thanks Phil!, when I tried this implementation before, I was not getting log and so thought its not refreshing. I answered for that part below
– salesforce-sas
Sep 26 at 10:04
add a comment
|
To make refreshApex clear the client-side cache it is necessary to capture and store the entire result from the getRecord wire. In this case you cannot define your handler to accept an anonymous object with data and error properties.
You need to do something like the following. First add a private property to hold the result:
_getRecordResponse;
Then update the handling of the getRecord wire response from something like:
@wire(getRecord, ...)
receiveRecord(error, data)
...
to:
@wire(getRecord, ...)
receiveRecord(response)
this._getRecordResponse = response;
let error = response && response.error;
let data = response && response.data;
...
Now that you have the _getRecordResponse, you can force the record to be reloaded by calling:
refreshApex(this._getRecordResponse);
To make refreshApex clear the client-side cache it is necessary to capture and store the entire result from the getRecord wire. In this case you cannot define your handler to accept an anonymous object with data and error properties.
You need to do something like the following. First add a private property to hold the result:
_getRecordResponse;
Then update the handling of the getRecord wire response from something like:
@wire(getRecord, ...)
receiveRecord(error, data)
...
to:
@wire(getRecord, ...)
receiveRecord(response)
this._getRecordResponse = response;
let error = response && response.error;
let data = response && response.data;
...
Now that you have the _getRecordResponse, you can force the record to be reloaded by calling:
refreshApex(this._getRecordResponse);
answered Sep 26 at 9:20
Phil WPhil W
5,4971 gold badge6 silver badges15 bronze badges
5,4971 gold badge6 silver badges15 bronze badges
Worth also noting you might be able to listen for changes in the backend using the Emp service - basically using streaming API and a change event.
– Phil W
Sep 26 at 9:27
Thanks Phil!, when I tried this implementation before, I was not getting log and so thought its not refreshing. I answered for that part below
– salesforce-sas
Sep 26 at 10:04
add a comment
|
Worth also noting you might be able to listen for changes in the backend using the Emp service - basically using streaming API and a change event.
– Phil W
Sep 26 at 9:27
Thanks Phil!, when I tried this implementation before, I was not getting log and so thought its not refreshing. I answered for that part below
– salesforce-sas
Sep 26 at 10:04
Worth also noting you might be able to listen for changes in the backend using the Emp service - basically using streaming API and a change event.
– Phil W
Sep 26 at 9:27
Worth also noting you might be able to listen for changes in the backend using the Emp service - basically using streaming API and a change event.
– Phil W
Sep 26 at 9:27
Thanks Phil!, when I tried this implementation before, I was not getting log and so thought its not refreshing. I answered for that part below
– salesforce-sas
Sep 26 at 10:04
Thanks Phil!, when I tried this implementation before, I was not getting log and so thought its not refreshing. I answered for that part below
– salesforce-sas
Sep 26 at 10:04
add a comment
|
Extending answer from @Phil W,
For below Sample LWC Js:
@api recordId = '00128000009j45tAAA';
@track wiredAccount;
fields = [ACCOUNT_NAME_FIELD, ACCOUNT_DESCRIPTION_FIELD];
@wire(getRecord, recordId: '$recordId', fields: '$fields' )
fetchAcc(response)
console.log('Account => ', JSON.stringify(response));
this.wiredAccount = response;
refreshWire()
refreshApex(this.wiredAccount);
Although we invoke refreshWire
, the wired method fetchAcc
will be invoked ONLY if new record and UI record in this.wiredAccount
are not same and consecutively see the console log. If the new record is same as UI record this.wiredAccount
, the method fetchAcc
will not be invoked (even after 30 seconds) and we will not see any console log. Finally, refreshApex should have been named refreshWire as it not just updates apex method response but also wired service response.
refreshApex is, I would presume, called refreshApex because both imperative and wired calls are fundamentally both just calling a (cacheable) AuraEnabled Apex method. The difference with a wired service is that there is client-side logic for handling caching (and for detecting changes to wired "reactive" parameters for re-invocation).
– Phil W
Sep 26 at 10:25
@PhilW So, you meangetRecord
is internally apex method in lightning namespace ?
– salesforce-sas
Sep 26 at 10:31
Yeah, I would think so. It seems like Salesforce is generally pretty good at using its own plumbing to implement stuff. Obviously I can't guarantee this since I've not seen the code, but it makes sense to do it this way.
– Phil W
Sep 26 at 10:49
crap.. this is good.. I was doing eval('$A.force.refreshView`)
– Pranay Jaiswal
Sep 26 at 15:52
add a comment
|
Extending answer from @Phil W,
For below Sample LWC Js:
@api recordId = '00128000009j45tAAA';
@track wiredAccount;
fields = [ACCOUNT_NAME_FIELD, ACCOUNT_DESCRIPTION_FIELD];
@wire(getRecord, recordId: '$recordId', fields: '$fields' )
fetchAcc(response)
console.log('Account => ', JSON.stringify(response));
this.wiredAccount = response;
refreshWire()
refreshApex(this.wiredAccount);
Although we invoke refreshWire
, the wired method fetchAcc
will be invoked ONLY if new record and UI record in this.wiredAccount
are not same and consecutively see the console log. If the new record is same as UI record this.wiredAccount
, the method fetchAcc
will not be invoked (even after 30 seconds) and we will not see any console log. Finally, refreshApex should have been named refreshWire as it not just updates apex method response but also wired service response.
refreshApex is, I would presume, called refreshApex because both imperative and wired calls are fundamentally both just calling a (cacheable) AuraEnabled Apex method. The difference with a wired service is that there is client-side logic for handling caching (and for detecting changes to wired "reactive" parameters for re-invocation).
– Phil W
Sep 26 at 10:25
@PhilW So, you meangetRecord
is internally apex method in lightning namespace ?
– salesforce-sas
Sep 26 at 10:31
Yeah, I would think so. It seems like Salesforce is generally pretty good at using its own plumbing to implement stuff. Obviously I can't guarantee this since I've not seen the code, but it makes sense to do it this way.
– Phil W
Sep 26 at 10:49
crap.. this is good.. I was doing eval('$A.force.refreshView`)
– Pranay Jaiswal
Sep 26 at 15:52
add a comment
|
Extending answer from @Phil W,
For below Sample LWC Js:
@api recordId = '00128000009j45tAAA';
@track wiredAccount;
fields = [ACCOUNT_NAME_FIELD, ACCOUNT_DESCRIPTION_FIELD];
@wire(getRecord, recordId: '$recordId', fields: '$fields' )
fetchAcc(response)
console.log('Account => ', JSON.stringify(response));
this.wiredAccount = response;
refreshWire()
refreshApex(this.wiredAccount);
Although we invoke refreshWire
, the wired method fetchAcc
will be invoked ONLY if new record and UI record in this.wiredAccount
are not same and consecutively see the console log. If the new record is same as UI record this.wiredAccount
, the method fetchAcc
will not be invoked (even after 30 seconds) and we will not see any console log. Finally, refreshApex should have been named refreshWire as it not just updates apex method response but also wired service response.
Extending answer from @Phil W,
For below Sample LWC Js:
@api recordId = '00128000009j45tAAA';
@track wiredAccount;
fields = [ACCOUNT_NAME_FIELD, ACCOUNT_DESCRIPTION_FIELD];
@wire(getRecord, recordId: '$recordId', fields: '$fields' )
fetchAcc(response)
console.log('Account => ', JSON.stringify(response));
this.wiredAccount = response;
refreshWire()
refreshApex(this.wiredAccount);
Although we invoke refreshWire
, the wired method fetchAcc
will be invoked ONLY if new record and UI record in this.wiredAccount
are not same and consecutively see the console log. If the new record is same as UI record this.wiredAccount
, the method fetchAcc
will not be invoked (even after 30 seconds) and we will not see any console log. Finally, refreshApex should have been named refreshWire as it not just updates apex method response but also wired service response.
answered Sep 26 at 10:03
salesforce-sassalesforce-sas
14.3k2 gold badges5 silver badges30 bronze badges
14.3k2 gold badges5 silver badges30 bronze badges
refreshApex is, I would presume, called refreshApex because both imperative and wired calls are fundamentally both just calling a (cacheable) AuraEnabled Apex method. The difference with a wired service is that there is client-side logic for handling caching (and for detecting changes to wired "reactive" parameters for re-invocation).
– Phil W
Sep 26 at 10:25
@PhilW So, you meangetRecord
is internally apex method in lightning namespace ?
– salesforce-sas
Sep 26 at 10:31
Yeah, I would think so. It seems like Salesforce is generally pretty good at using its own plumbing to implement stuff. Obviously I can't guarantee this since I've not seen the code, but it makes sense to do it this way.
– Phil W
Sep 26 at 10:49
crap.. this is good.. I was doing eval('$A.force.refreshView`)
– Pranay Jaiswal
Sep 26 at 15:52
add a comment
|
refreshApex is, I would presume, called refreshApex because both imperative and wired calls are fundamentally both just calling a (cacheable) AuraEnabled Apex method. The difference with a wired service is that there is client-side logic for handling caching (and for detecting changes to wired "reactive" parameters for re-invocation).
– Phil W
Sep 26 at 10:25
@PhilW So, you meangetRecord
is internally apex method in lightning namespace ?
– salesforce-sas
Sep 26 at 10:31
Yeah, I would think so. It seems like Salesforce is generally pretty good at using its own plumbing to implement stuff. Obviously I can't guarantee this since I've not seen the code, but it makes sense to do it this way.
– Phil W
Sep 26 at 10:49
crap.. this is good.. I was doing eval('$A.force.refreshView`)
– Pranay Jaiswal
Sep 26 at 15:52
refreshApex is, I would presume, called refreshApex because both imperative and wired calls are fundamentally both just calling a (cacheable) AuraEnabled Apex method. The difference with a wired service is that there is client-side logic for handling caching (and for detecting changes to wired "reactive" parameters for re-invocation).
– Phil W
Sep 26 at 10:25
refreshApex is, I would presume, called refreshApex because both imperative and wired calls are fundamentally both just calling a (cacheable) AuraEnabled Apex method. The difference with a wired service is that there is client-side logic for handling caching (and for detecting changes to wired "reactive" parameters for re-invocation).
– Phil W
Sep 26 at 10:25
@PhilW So, you mean
getRecord
is internally apex method in lightning namespace ?– salesforce-sas
Sep 26 at 10:31
@PhilW So, you mean
getRecord
is internally apex method in lightning namespace ?– salesforce-sas
Sep 26 at 10:31
Yeah, I would think so. It seems like Salesforce is generally pretty good at using its own plumbing to implement stuff. Obviously I can't guarantee this since I've not seen the code, but it makes sense to do it this way.
– Phil W
Sep 26 at 10:49
Yeah, I would think so. It seems like Salesforce is generally pretty good at using its own plumbing to implement stuff. Obviously I can't guarantee this since I've not seen the code, but it makes sense to do it this way.
– Phil W
Sep 26 at 10:49
crap.. this is good.. I was doing eval('$A.force.refreshView`)
– Pranay Jaiswal
Sep 26 at 15:52
crap.. this is good.. I was doing eval('$A.force.refreshView`)
– Pranay Jaiswal
Sep 26 at 15:52
add a comment
|
Thanks for contributing an answer to Salesforce Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f279516%2fhow-to-refresh-wired-service-getrecord-manually%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown