Skip to content

Instantly share code, notes, and snippets.

@pranayjswl007
Last active April 8, 2019 16:17
Show Gist options
  • Save pranayjswl007/cb398cb04f527c2f5280c2c7ca924e41 to your computer and use it in GitHub Desktop.
Save pranayjswl007/cb398cb04f527c2f5280c2c7ca924e41 to your computer and use it in GitHub Desktop.
Refresh Apex without any change in Database.
<template>
<lightning-input label={realFormData.FirstName} value={realFormData.FirstName} if:true={realFormData} onchange={updateValue}></lightning-input>
<button class="slds-button" onclick={myRefreshFunction}> Cancle edit</button>
</template>
import { LightningElement ,wire,track,api } from 'lwc';
import myContact from "@salesforce/apex/ContactController.fetchContact";
import { refreshApex } from '@salesforce/apex';
export default class Myrefreshapextest extends LightningElement {
@api wiredContact;
@api realFormData;
@wire (myContact)
fetchedContacts(resp){
this.wiredContact = resp;
this.realFormData = {... this.wiredContact.data};
}
updateValue(event){
this.realFormData = {...this.realFormData , FirstName: event.detail.value};
}
@api
myRefreshFunction(event ){
console.log('Refresh Apex called');
refreshApex(this.wiredContact);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment