I have a scenario, wherein I display a Warning message using toast when the record is updated to meet certain criteria. I am trying to use a combination of @wire and imperative apex.
Below is the code snippet:
@api recordId; bShowToast = false; error; @wire (getRecord, {recordId : '$recordId' ,fields: [ 'Claim__c.StartDate__c']}) getClaimRecord({error , data}){ if(data){ // eslint-disable-next-line no-console console.log('data : ' ,data); }else if(error){ this.error = error; } this.showToast(); } showToast() { verifyEndDate({sClaimId: this.recordId}) //imperative apex call .then(result =>{ // eslint-disable-next-line no-console console.log('result : ' ,result); this.bShowToast = result; // eslint-disable-next-line no-console console.log('bShowToast : ' ,this.bShowToast); if(this.bShowToast){ this.dispatchEvent( new ShowToastEvent({ title: 'Get Help', message: 'ACTION REQUIRED...', }) ); } }) .catch(error => { // eslint-disable-next-line no-console console.log('Error Occured : ' ,error); }); } I send the value from apex method to display toast based on certain values on the record (majorly depend on changes to a single field).
Now, the problem is that it retains the value from very first apex call and the value doesn't change even if the back-end method is supposed to send other value. Eg: if on page/component load - the method returns true, it'll display same value even if I update the record to make the value as false. I tried using refreshApex() but that didn't work for me.
Any idea how this can be achieved.
When trying to use Aura component to force refresh.. I can't even find the aura component on custom component list. I have no experience with aura and directly started with LWC.. Below is the code for aura components:
<aura:component > <c:claimWarningMessage onrecordChange="{!c.refreshView}" ></c:claimWarningMessage> </aura:component> CONTROLLER:
({ refreshView: function(component, event) { // refresh the view $A.get('e.force:refreshView').fire(); } }) I added below line in showToast() method...
this.dispatchEvent(new CustomEvent('recordChange'));
Any idea why I'm not able to see the component in custom component list?