0

i want to create account records using lwc with its 6 fields. code was deployed successfully but when i deployed it on page it gives error-the page has error you might need to refresh it.

here is my code

<template>
<lightning-record-form  object-api-name={accountobject} columns ="2"
fields={fields} onsuccess={handleclick}  >
 </lightning-record-form>
 </template>

createandUpdate.js

  import { LightningElement} from 'lwc';
  import Account_OBJECT from '@salesforce/schema/account';
   import NAME_FIELD from '@salesforce/schema/account.name';
   import Revenue_FIELD from '@salesforce/schema/account.annualRevenue';
  import TYPE_FIELD from '@salesforce/schema/account.type';
   import INDUSTRY_FIELD from '@salesforce/schema/account.Industry';
  import Description_FIELD from '@salesforce/schema/account.Description';
  import Phone_FIELD from '@salesforce/schema/account.Phone';
  import {showToastEvent} from 'lightning/platformshowToastEvent';

  export default class CreateandUpdate extends LightningElement {
  accountobject=Account_OBJECT;

fields=[NAME_FIELD,Revenue_FIELD,TYPE_FIELD,INDUSTRY_FIELD,Description_FIELD,Phone_FIELD];
handleclick(){
    const evt = new ShowToastEvent({
        title:"account creted successfully",
        variant: "success",
        message:"record inserted",

    });
    this.dispatchEvent(evt);

   }

}

createandUpdate.xml

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>51.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__RecordPage</target>
 <target>lightning__HomePage</target>
  <target>lightning__AppPage</target>
</targets>

 </LightningComponentBundle>

help me out where i am going wrong

1 Answer 1

0

The object-api-name must be of type String and not the object. So you need to change the below line

accountobject=Account_OBJECT;

To

accountobject=Account_OBJECT.apiName;
2
  • this wouldn't work for me Commented Apr 28, 2021 at 6:50
  • @ShivaniTanwar are you getting any error here? did you debug your code? Commented Apr 28, 2021 at 6:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .