本篇参考:

https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.reference_get_record_notify

https://developer.salesforce.com/docs/component-library/documentation/en/lwc/reference_notify_record_update

我们在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

总结:尽管官方弃用了此方法,但是没有提及后续会移除此方法,所以以前的方法可以保留,后续的话,推荐使用新方法。篇中有错误欢迎指出,有不懂欢迎留言。

最新文章

  1. Oracle分页语句
  2. poj1068 模拟
  3. 【双标记线段树】bzoj1798维护序列seq
  4. 使用JMeter进行负载测试——终极指南
  5. 使用APUE(UNIX高级编程)源代码
  6. 部分SIM卡被曝存安全漏洞:7.5亿部手机受牵连
  7. sublime3快捷键
  8. jquery ajax json简单的分页,模拟数据,没有封装,只显示原理
  9. Android Activity学习笔记(一)
  10. Aspose.Cells.dll引用导入导出Excel
  11. 查看linux服务器版本
  12. 设置符合条件的DataGridView的行的颜色的两种方法
  13. 568. Maximum Vacation Days
  14. React 关于组件(界面)更新
  15. python联系-迭代器
  16. flask上下文(new)
  17. Linux vi/vim编辑器
  18. (链表 双指针) leetcode 19. Remove Nth Node From End of List
  19. 如何在win+r 或者是win10的应用搜索输入subl就能打开sublime
  20. 嵌套for

热门文章

  1. SQLSever视图和存储过程
  2. CB利用链及无依赖打Shiro
  3. 基于k8s的发布系统的实现
  4. UED Landing 页 - 定时抓取掘金文章
  5. 剖析一下&quot;抢茅台&quot;脚本底层逻辑
  6. Xamarin.Android带参数返回上一级界面
  7. &lt;二&gt;派生类的构造过程
  8. Promise基础知识
  9. Leanote蚂蚁笔记-私人云笔记服务器搭建
  10. include指令和include动作的区别