function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kallam salesforce1kallam salesforce1 

Unable 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 {
getDetials
columns =[
    {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)
    }
    );
}
}

 
MagulanDuraipandianMagulanDuraipandian
Kallam,
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