我正在开发一个 Salesforce Lightning Web 组件 (LWC),旨在嵌入到屏幕流中。该组件允许用户修改帐户记录的字段,然后使用 Apex 控制器方法 updateAccount() 更新记录。该组件还应该将更新的帐户记录传递到流程中的下一个屏幕。但是,我面临一个问题,流程中的下一个屏幕仍然显示旧的帐户值,而不反映 LWC 中所做的更新。 尽管更新操作成功完成(通过显示更新后的帐户记录的控制台日志确认),但流程中的后续屏幕不会反映这些更新。
要点:
LWC 旨在从父流接收帐户记录,允许字段修改,然后通过控制器中的 updateAccount() 更新帐户。
验证方法调用handleSaveEvent()来进行更新。成功更新后,saveSuccess 将设置为 true,并调度 FlowAttributeChangeEvent 以向流发出更新信号。
Account 属性的输入和输出配置均在组件的元数据中设置,旨在组件和流屏幕之间的数据流连续性。
尽管更新操作明显成功(通过 saveSuccess 验证),但后续流程屏幕并未显示更新的帐户数据。
我怀疑这个问题可能与更新的数据在后续流程屏幕中的通信和呈现方式有关,特别是考虑到涉及验证和事件分派的顺序。
相关代码片段: 用于更新帐户和验证处理的 JavaScript:
@api account;
@api isUpdateNeeded = false;
saveSuccess = true;
@api
validate() {
this.handleSaveEvent();
if (this.saveSuccess) {
// Logic to proceed to the next screen, assuming validation passes
return { isValid: true };
} else {
// Logic to handle validation failure
return {
isValid: false,
errorMessage: 'Failed to update Account data.'
};
}
}
@api
async handleSaveEvent() {
this.checkForChange(); // Determines if update based on field changes is needed
if (this.isUpdateNeeded) {
this.updatePayload.Id = this.account.Id;
try {
await updateAccount({ account: this.updatePayload });
let help = {...this.account};
help = Object.assign(help,this.updatePayload);
this.account = help;
console.log('Updated Account:', JSON.stringify(this.account)); // Confirms the Account update in console
// Logic to handle successful Account update
this.saveSuccess = true;
notifyRecordUpdateAvailable([{ recordId: this.account.Id }]);
// Dispatching FlowAttributeChangeEvent to signal data update
this.dispatchEvent(new FlowAttributeChangeEvent('account', this.account));
} catch (error) {
// Error handling logic
this.saveSuccess = false;
}
}
}
流配置的组件元数据:
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__FlowScreen</target>
</targets>
<targetConfigs>
<targetConfig targets="lightning__FlowScreen">
<property name="account" type="@salesforce/schema/Account" label="Account" description="The Account record for modification" required="true"/>
</targetConfig>
</targetConfigs>
</LightningComponentBundle>
虽然更新过程似乎运行正常,并且我使用验证逻辑和事件调度的组合来发出更新信号,但流程中的下一个屏幕不会显示更新的帐户值。如何确保流程在验证并进入下一个屏幕后准确反映更新的帐户数据?
你能给我完整的html代码吗