0

Let's say in my custom aura component, There's a spinner that indicates that we're still processing your record. What I want to happen is if that aura component is still open in a tab and a record that is related to that page is updated. I want to automatically reload the page. What I've tried so far are the following

1.) setInterval function - in my doInit method i have a setInterval function that calls a method in the controller class wherein I try to query the record to check if it was updated or not. Which doesn't work because it's not returning any data maybe because of the combination of setInveral and callbacks.

Controller

    setInterval(function(){
        helper.CheckIfRecordIsUpdated(component,event,helper);
    }, 
    5000);

Helper

function checkIfRecordIsUpdated(component,event,helper){
var recordId = component.get("v.recordId");
var getNewStatus= component.get("c.getNewStatus");
getNewStatus.params({"recordId" : recordId})
getNewStatus.setCallback(this,function(response){
//DOES NOT ENTER HERE
});
$A.enqueueAction(getNewStatus);
}

2.) force:recordData - The issue with force:recordData is it will only detect the change on the record if i refresh the page.

<force:recordData
              recordId="{!v.recordId}"
              targetFields="recordField"
              recordUpdated="{!c.recordUpdate}" />

Is there anyway for me to achieve this? Is this even possible in aura component?

1
  • Try Change Data Capture. – Rahul Gawale Feb 25 at 12:31
1

For 2) at the moment, LDS only detects changes done through Aura, LWC or the standard salesforce UI (which are lightning components indeed). That means that your change, being done through an API won't be detected. There's a feature salesforce is working on to overcome that --> see LWC Force Refresh Wire getRecord

For 1) you will have to use $A.getCallback --> see https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_cb_mod_ext_js.htm and https://www.jitendrazaa.com/blog/salesforce/calling-apex-method-at-regular-interval-from-lightning-component/

1
  • Thanks!! It works now! – imajmdf Feb 25 at 14:52

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.