You need to sign in to do that
Don't have an account?
Madan51
Error while creating a new custom object record by using LWC
I created an LWC to create a new record for a standard object, i am able to create successfully for an account object.But its throwing an error while creating a new record .
Here is the code i wrote :
FOR ACCOUNT OBJECT:
HTML file:--
<template>
<Lightning-record-form
object-api-name={accountobject}
fields={fields}
onsuccess={handleAccountCreate}>
</Lightning-record-form>
</template>
JS file :--
import { LightningElement } from 'lwc';
import ACCOUNT_OBJECT from '@salesforce/schema/Account';
import NAME_FIELD from '@salesforce/schema/Account.Name';
import WEBSITE_FIELD from '@salesforce/schema/Account.Website';
export default class CreateNewRecord extends LightningElement {
accountobject = ACCOUNT_OBJECT;
fields =[NAME_FIELD , WEBSITE_FIELD];
handleAccountCreate(){
}
}
For the above piece of code its working fine.But for the below code for a custom object record creation
HTML file :--
<template>
<Lightning-record-form object-api-name={objectApiName}
fields={fields}
onsuccess={handleSuccess}>
</Lightning-record-form>
</template>
JS file :--
import { LightningElement ,api } from 'lwc';
import {ShowToastEvent} from 'Lightning/platformShowToastEvent';
import AREA__c_OBJECT from '@salesforce/schema/Area__c';
import NAME_FIELD from '@salesforce/schema/Area__c.Name';
import PINCODE_FIELD from '@salesforce/schema/Area__c.pincode__c';
export default class CustomeObjectRecordCreate extends LightningElement {
@api objectApiName;
AreaName = AREA__c_OBJECT;
fields = [NAME_FIELD , PINCODE_FIELD];
handleSuccess(event){
const evt = new ShowToastEvent({
title:"record created",
message:event.detail.NAME_FIELD,
variant:"success"
});
this.dispatchEvent(evt);
}
}
in the code above "Area " is the name of custome object.and Name and pincode are the fields in custom object.
Plz help me for that.thanks in advance.
Here is the code i wrote :
FOR ACCOUNT OBJECT:
HTML file:--
<template>
<Lightning-record-form
object-api-name={accountobject}
fields={fields}
onsuccess={handleAccountCreate}>
</Lightning-record-form>
</template>
JS file :--
import { LightningElement } from 'lwc';
import ACCOUNT_OBJECT from '@salesforce/schema/Account';
import NAME_FIELD from '@salesforce/schema/Account.Name';
import WEBSITE_FIELD from '@salesforce/schema/Account.Website';
export default class CreateNewRecord extends LightningElement {
accountobject = ACCOUNT_OBJECT;
fields =[NAME_FIELD , WEBSITE_FIELD];
handleAccountCreate(){
}
}
For the above piece of code its working fine.But for the below code for a custom object record creation
HTML file :--
<template>
<Lightning-record-form object-api-name={objectApiName}
fields={fields}
onsuccess={handleSuccess}>
</Lightning-record-form>
</template>
JS file :--
import { LightningElement ,api } from 'lwc';
import {ShowToastEvent} from 'Lightning/platformShowToastEvent';
import AREA__c_OBJECT from '@salesforce/schema/Area__c';
import NAME_FIELD from '@salesforce/schema/Area__c.Name';
import PINCODE_FIELD from '@salesforce/schema/Area__c.pincode__c';
export default class CustomeObjectRecordCreate extends LightningElement {
@api objectApiName;
AreaName = AREA__c_OBJECT;
fields = [NAME_FIELD , PINCODE_FIELD];
handleSuccess(event){
const evt = new ShowToastEvent({
title:"record created",
message:event.detail.NAME_FIELD,
variant:"success"
});
this.dispatchEvent(evt);
}
}
in the code above "Area " is the name of custome object.and Name and pincode are the fields in custom object.
Plz help me for that.thanks in advance.
The error i am getting is "Invalid refference Area__c.pincode__c of type SobjectField in file LwcName.js"
here Area (custom object),pincode custom field and LwcName (name of my LWC).
This is the extension for my above question.