Salesforce LWC学习(四十二) getRecordNotifyChange已弃用
本篇参考:
我们在Salesforce LWC学习(二十九) getRecordNotifyChange(LDS拓展增强篇)中讲述了针对LDS通知获取最新版本数据使用。在winter23的v56版本中,此方法还在正常使用,在 spring23的v57版本中,getRecordNotifyChange方法已被标记弃用,官方推荐notifyRecordUpdateAvailable方法,功能相同。
notifyRecordUpdateAvailable方法和 getRecordNotifyChange传递形参一样,针对此方法,分成两步走。
1. 头部引入:import { notifyRecordUpdateAvailable } from 'lightning/uiRecordApi';
2. 需要刷新的地方使用:notifyRecordUpdateAvailable(items: Array<{recordId: string}>)
需要注意的是, recordId同样需要在user interface api支持的,否则不生效。
详情:https://developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/ui_api_all_supported_objects.htm
接下来demo进行参考。
import { LightningElement, wire,api,track } from 'lwc';
import { getRecord,notifyRecordUpdateAvailable } from 'lightning/uiRecordApi';
import { refreshApex } from '@salesforce/apex';
import saveAccount from '@salesforce/apex/RecordNotifyChangeController.saveAccount';
import getAccount from '@salesforce/apex/RecordNotifyChangeController.getAccount';
import PHONE_FIELD from '@salesforce/schema/Account.Phone';
import INDUSTRY_FIELD from '@salesforce/schema/Account.Industry';
import NAME_FIELD from '@salesforce/schema/Account.Name';
export default class RecordNotifyChangeSample extends LightningElement {
@api recordId;
@track phone;
@track industry;
@track accountName;
fields=[PHONE_FIELD,INDUSTRY_FIELD];
accountRecord; @wire(getAccount,{recordId : '$recordId'})
wiredAccount(value) {
this.accountRecord = value;
const { data, error } = value;
if(data) {
this.industry = data.Industry;
this.phone = data.Phone;
this.accountName = data.Name;
}
} handleChange(event) {
if(event.target.name === 'phone') {
this.phone = event.detail.value;
} else if(event.target.name === 'industry') {
this.industry = event.detail.value;
}
} async handleSave() {
await saveAccount({ recordId: this.recordId, industry : this.industry, phone : this.phone})
.then(result => {
if(result === 'success') {
refreshApex(this.accountRecord);
notifyRecordUpdateAvailable([{recordId: this.recordId}]);
} else {
//TODO
}
})
.catch(error => {
//TODO
});
} }
详情demo可以参考:https://boulder-bard-27f.notion.site/lightning-e757a8902c194f9bbe633b92a9d81673
总结:尽管官方弃用了此方法,但是没有提及后续会移除此方法,所以以前的方法可以保留,后续的话,推荐使用新方法。篇中有错误欢迎指出,有不懂欢迎留言。
最新文章
- Oracle分页语句
- poj1068 模拟
- 【双标记线段树】bzoj1798维护序列seq
- 使用JMeter进行负载测试——终极指南
- 使用APUE(UNIX高级编程)源代码
- 部分SIM卡被曝存安全漏洞:7.5亿部手机受牵连
- sublime3快捷键
- jquery ajax json简单的分页,模拟数据,没有封装,只显示原理
- Android Activity学习笔记(一)
- Aspose.Cells.dll引用导入导出Excel
- 查看linux服务器版本
- 设置符合条件的DataGridView的行的颜色的两种方法
- 568. Maximum Vacation Days
- React 关于组件(界面)更新
- python联系-迭代器
- flask上下文(new)
- Linux vi/vim编辑器
- (链表 双指针) leetcode 19. Remove Nth Node From End of List
- 如何在win+r 或者是win10的应用搜索输入subl就能打开sublime
- 嵌套for