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
总结:尽管官方弃用了此方法,但是没有提及后续会移除此方法,所以以前的方法可以保留,后续的话,推荐使用新方法。篇中有错误欢迎指出,有不懂欢迎留言。
Salesforce LWC学习(四十二) getRecordNotifyChange已弃用的更多相关文章
- Salesforce LWC学习(四十) dynamic interaction 浅入浅出
本篇参考: Configure a Component for Dynamic Interactions in the Lightning App Builder - Salesforce Light ...
- Salesforce LWC学习(三十二)实现上传 Excel解析其内容
本篇参考:salesforce lightning零基础学习(十七) 实现上传 Excel解析其内容 上一篇我们写了aura方式上传excel解析其内容.lwc作为salesforce的新宠儿,逐渐的 ...
- Salesforce LWC学习(四十) datatable的dynamic action的小坑浅谈
本篇参考:https://developer.salesforce.com/docs/component-library/bundle/lightning-datatable/documentatio ...
- Salesforce LWC学习(四十一) If:true 即将弃用?
本篇参考: https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.reference_dir ...
- Salesforce LWC学习(三十) lwc superbadge项目实现
本篇参考:https://trailhead.salesforce.com/content/learn/superbadges/superbadge_lwc_specialist 我们做lwc的学习时 ...
- Salesforce LWC学习(三十九) lwc下quick action的recordId的问题和解决方案
本篇参考: https://developer.salesforce.com/docs/component-library/bundle/force:hasRecordId/documentation ...
- Salesforce LWC学习(三十六) Quick Action 支持选择 LWC了
本篇参考: https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.use_quick_act ...
- Java开发学习(四十二)----MyBatisPlus查询语句之条件查询
一.条件查询的类 MyBatisPlus将书写复杂的SQL查询条件进行了封装,使用编程的形式完成查询条件的组合. 这个我们在前面都有见过,比如查询所有和分页查询的时候,都有看到过一个Wrapper类, ...
- Salesforce LWC学习(三十四) 如何更改标准组件的相关属性信息
本篇参考: https://www.cnblogs.com/zero-zyq/p/14548676.html https://www.lightningdesignsystem.com/platfor ...
- Salesforce LWC学习(四) 父子component交互 / component声明周期管理 / 事件处理
我们在上篇介绍了 @track / @api的区别.在父子 component中,针对api类型的变量,如果声明以后就只允许在parent修改,son component修改便会导致报错. sonIt ...
随机推荐
- tostring、(string)和 String.valueOf()
上周遇到一个问题,只怪自己平时没注意这个细节,从数据库取数据在map集合里,取出该值是我用了.tostring的方法,一次在当取出数据为空时代码报java.lang.NullPointerExcept ...
- pyftpdlib中文乱码问题解决方案
python实现简易的FTP服务器 from pyftpdlib.authorizers import DummyAuthorizer from pyftpdlib.handlers import F ...
- java并发数据结构之CopyOnWriteArrayList
CopyOnWriteArrayList是一个线程安全的List实现,其在对对象进行读操作时,由于对象没有发生改变,因此不需要加锁,反之在对象进行增删等修改操作时,它会先复制一个对象副本,然后对副本进 ...
- Mybatis-Plus 对 json 的存储使用支持
Mybatis-Plus 对 json 的存储使用支持 场景分析: 随着数据库对字段类型支持的多元化,json 类型的存储已成为多场景高频使用的字段类型.而 MySql.postgrpSql 等都支持 ...
- CountDownLatch闭锁源码解析(基于jdk11)
目录 CountDownLatch闭锁源码解析(基于jdk11) 1.1 CountDownLatch概述 1.2 CountDownLatch原理 1.2.1 基本结构(jdk11) 1.2.2 a ...
- requests模块和openpyxl模块
第三方模块的下载和使用 1,第三方模块就是别人大神们已经写好的模块,功能特别强大.我们如果像使用第三方模块就先要进行下载.下载完成后 才可以在python中直接调用 2.下载方式一:pip工具 pip ...
- express 为所有路由添加 405 method not allowd 响应
背景知识 HTTP Status Code 405 405 Method not allowed The resource was requested using a method that is n ...
- 错误:Required request parameter 'XXX' for method parameter type String is not present
错误信息:Required request parameter 'XXX' for method parameter type String is not present 这种都是前端请求方式不同,后 ...
- MAUI新生4.6-主题设置LightTheme&DarkTheme
通过主题设置,可以在运行时更改应用的主题外观,比如切换亮色主题和暗黑主题.主题设置并没有新的知识点,基本的原理如下: 定义每个应用主题的ResourceDictionary,每个ResourceDic ...
- JavaScript:箭头函数:作为参数进行传参
之前已经说过,JS的函数,也是对象,而函数名是一个变量,是可以进行传参的,也即函数是可以被传参的. 只要是函数,都可以被传参,但是箭头函数的语法更为灵活,所以更方便进行传参. 如上图所示,fun1是一 ...