我是LWC的新手,想知道为什么我的代码无法正常工作。我的要求是从VF页面调用此LWC。使用LWC,我必须在对象PRODUCT2__C中创建一个新记录。 我已经附上了我的LWC的javascript和html文件。当我遇到错误时,请告诉我我在做什么错: “创建记录时出错 尝试更新记录时发生错误。请重试。”
// tUButton.html
<!--
@File Name : tUButton.html
@Description :
@Author : ChangeMeIn@UserSettingsUnder.SFDoc
@Group :
@Last Modified By : ChangeMeIn@UserSettingsUnder.SFDoc
@Last Modified On : 12/10/2019, 12:49:09 PM
@Modification Log :
Ver Date Author Modification
1.0 12/9/2019 ChangeMeIn@UserSettingsUnder.SFDoc Initial Version
-->
<template>
<lightning-card title="Add Number of Layers And Palletes" icon-name="standard:record">
<div class="slds-m-around_medium">
<lightning-input label="Id" disabled value={Product2}></lightning-input>
<lightning-input label="TU per Layer" onchange={handleChangeLayer} class="slds-m-bottom_x-small"></lightning-input>
<lightning-input label="Layer per Pallete" onchange={handleChangePallete} class="slds-m-bottom_x-small"></lightning-input>
<lightning-button label="Submit" variant="brand" onclick={submitProduct}></lightning-button>
</div>
</lightning-card>
</template>
// tUButton.js
//
import { LightningElement, track, api } from 'lwc';
import { createRecord } from 'lightning/uiRecordApi';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import Product2_OBJECT from '@salesforce/schema/Product2';
import NAME_FIELD from '@salesforce/schema/Product2.Name';
//import SKULayers_FIELD from '@salesforce/schema/Product2.SKU_External_Id__c'
export default class LdsCreateRecord extends LightningElement {
// @track productId;
@track name = '';
@api recordId;
handleChangeLayer(event) {
this.productId = undefined;
this.name = event.target.value;
}
handleChangePallete(event) {
this.productId = undefined;
this.name = event.target.value;
}
submitProduct() {
const fields = {};
fields[NAME_FIELD.fieldApiName] = this.name;
const recordInput = { apiName: Product2_OBJECT.objectApiName, fields };
createRecord(recordInput)
.then(product => {
this.productId = product.id;
this.dispatchEvent(
new ShowToastEvent({
title: 'Success',
message: 'Product created',
variant: 'success',
}),
);
})
.catch(error => {
this.dispatchEvent(
new ShowToastEvent({
title: 'Error creating record',
message: error.body.message,
variant: 'error',
}),
);
});
}
}
如果有人能帮助您确定问题,请先感谢。