I have facilitated a button to create a record through a button with help of navigation Mixin. I need to refresh my data table with a record that has been created. I am trying to refresh the data, but the table is not getting refreshed.
datatable.html
<template>
<lightning-button
label="Looks Fine"
onclick={handleSelectedFields}
>
</lightning-button>
<lightning-button
variant="brand"
label="Add Row"
title="Primary action"
onclick={handleAddRow}
class="slds-m-left_x-small"
>
</lightning-button>
<lightning-datatable
key-field="id"
data={fetchedContacts}
columns={columns}
>
</lightning-datatable>
</template>
datatable.js
import { LightningElement, track, wire,api } from 'lwc';
import getRecords from '@salesforce/apex/ExploreCustomContactController.getRecords';
import getContactFields from '@salesforce/apex/ExploreCustomContactController.getContactFields';
import getFieldTypes from '@salesforce/apex/ExploreCustomContactController.getFieldTypes';
import { NavigationMixin } from 'lightning/navigation';
import { refreshApex } from '@salesforce/apex';
export default class ExploreReimplementDataTable extends NavigationMixin(LightningElement) {
@track columns = [
{ label: 'Id', fieldName: 'Id' },
{ label: 'Name', fieldName: 'Name' }
];
@track selected = ['Id','Name'];
@track fetchedContacts = [];
@api objectApiName;
refresh;
@wire(getContactFields , { objectApiName : '$objectApiName'}) wiredContactFields;
@wire(getRecords, { selectedFields: '$selected' , objectApiName: '$objectApiName'})
wiredContacts(result) {
this.refresh = result;
if (result.data) {
this.fetchedContacts = result.data;
console.log(this.fetchedContacts);
} else if (result.error) {
console.log(result.error);
}
}
handleAddRow(){
this[NavigationMixin.Navigate]({
type: 'standard__objectPage',
attributes: {
objectApiName: this.objectApiName,
actionName: 'new'
}
});
refreshApex(this.refresh);
}
}
I am not knowing how to refresh the table after creating record.