• Madan51
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
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.

 
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.