Favoritesriramreddy kallam (CapGemini) asked in #Lightning ExperienceJan 26, 2022, 6:27 AMUnable to refresh the table After deleting selected Record. Can someone help me how to refresh the data table?APEX Class>>>>>>>>>public with sharing class AccountManager { @AuraEnabled(cacheable=true) public static list<Account> getAccounts(){ list<Account> listAcc = [SELECT Id,Name,Rating,AnnualRevenue from Account LIMIT 8]; return listAcc; } @AuraEnabled public static void deleteselectedRecords(list<Id> listOfIds){ list<Account> listOfAcc = [SELECT Id,Name,Rating,AnnualRevenue from Account where ID IN : listOfIds]; if(!listOfAcc.isEmpty()){ delete listOfAcc; } }}html>>>>>>>>>>>>>>>>>><template> <lightning-card title="Delete selected Rows"> <lightning-datatable key-field="id" data={getDetials} columns={columns} onrowselection={onselctedRowHandler} > </lightning-datatable> <div class="slds-m-around_medium"> <lightning-button label="DeleteSelectedRecords" variant="brand" onclick={ClickDeleteRecords}></lightning-button> </div> </lightning-card></template>import { LightningElement,wire } from 'lwc';import getAccounts from '@salesforce/apex/AccountManager.getAccounts'import deleteselectedRecords from '@salesforce/apex/AccountManager.deleteselectedRecords'import {ShowToastEvent} from 'lightning/platformShowToastEvent';import { refreshApex } from '@salesforce/apex';export default class DeleteSelectedRows extends LightningElement {getDetialscolumns =[ {label:'Id',fieldName:'Id'}, {label:'AccName',fieldName:'Name'}, {label:'Rating',fieldName:'Rating'}, {label:'AnnualRevenue',fieldName:'AnnualRevenue'}];@wire (getAccounts) getAccdetails({data,error}){if(data){ this.getDetials = data; console.log(data) console.log(this.getDetials)}else{ console.log(error)}}seletedRowIdList =[]onselctedRowHandler(event){ const seletedRows = event.detail.selectedRows console.log(seletedRows) for(let i=0; i< seletedRows.length; i++){ this.seletedRowIdList.push(seletedRows[i].Id) console.log(this.seletedRowIdList) }}ClickDeleteRecords(){ deleteselectedRecords({listOfIds : this.seletedRowIdList}).then(()=> { const toastEvent = new ShowToastEvent({ title:'Success!', message:'Record deleted successfully', variant:'success' }); this.dispatchEvent(toastEvent); return refreshApex(this.getAccdetails); } ).catch((error)=>{ console.log(error) } );}} Show More1 answerSortSort by Most HelpfulSort by Most HelpfulSort by DateMagulan Duraipandian (Salesforce)Jan 26, 2022, 12:37 PMKallam,the following code is incorrect.return refreshApex(this.getAccdetails);You have to pass the wired data to refreshApex. Sample Code: https://www.infallibletechie.com/2021/07/how-to-get-updated-wired-data-in.htmlWrite an answer...BoldItalicUnderlineStrikethroughBulleted ListNumbered ListAdd linkCode blockInsert imageAttach filesLink URLCancelSave0/9000Reply
Magulan Duraipandian (Salesforce)Jan 26, 2022, 12:37 PMKallam,the following code is incorrect.return refreshApex(this.getAccdetails);You have to pass the wired data to refreshApex. Sample Code: https://www.infallibletechie.com/2021/07/how-to-get-updated-wired-data-in.html