You need to sign in to do that
Don't have an account?
Himanshu Ghate
Inside the console it giving me an error like-->{status: 400, body: {…}, headers: {…}, ok: false, statusText: 'Bad Request', …}
body: {message: 'An error occurred while trying to update the record. Please try again.', statusCode: 400, enhancedErrorType: 'RecordError', output: {…}}
errorType: "fetchResponse"
headers: {}
ok: false
status: 400
statusText: "Bad Request"
[[Prototype]]: Object
And Here is my code-->can Some one please let me know where the problem and How I can create the Account record.
Please Response with the soloution.
.html code
<template>
<!-- Form this we have created the Account record form, -->
<!-- but,Now as soon as the record the user will be inserted should be save -->
<lightning-layout>
<lightning-layout-item size="12">
<lightning-card title="AccountRecordForm">
<lightning-input type="text" label="Name" onchange={handleName}>
</lightning-input>
<lightning-input type="text" label="Phone" onchange={handlePhone}>
</lightning-input>
<lightning-button label="Save" onclick={handleSave}>
</lightning-button>
</lightning-card>
</lightning-layout-item>
</lightning-layout>
</template>
.js
import { LightningElement,api } from 'lwc';
import { createRecord } from 'lightning/uiRecordApi';
export default class LDSFormMaking1 extends LightningElement {
//Declare the variable
Name;
Phone;
//Now I want to store the data which user will be inserted into the
//Account Name-Rahul ,Phone-->784578455 As well as for the Save button
//So that Record should be save
//Now first I want to fetch the data of the User who is inserting the data
//in the Name text box i.eName-->Rahul(I want to store the Rahul inside the Name)
//So for that make the handleName inside the html.
handleName(event)
{
//For the Name ,when the user will inserted any data
//will be inside the Name text box
//1)--> User will insert the data inside the Name
//soon ,the user will be hitting the event
//2)--> That,insert value will be inside the event
this.Name=event.target.value; //From this, the user value will be inside the Name
}
handlePhone(event)
{
this.Phone=event.target.value; //From this, the User value phone will be inside the Phone
}
handleSave()
{
//Now Inside the Save button ,When ever the user will
//Inserting the value like the Name and Phone
//Should be Save the Record into the Salesforce Org.
//1)To Create the Record -->Fetch Create Record from the Lightning/uiRecordApi.
//Now How to create the object let see,Hit on lightning/uiRecordApi
//To create Record
//I need to fetch first Fields for that
let fields={'Name':this.Name,'Phone':this.Phone};
//Now I want to fetch whole Record so for that,
let Record={'apiName':'Account','Fields':fields};
//Now I want to send the record
//createRecord(Record); //From this you can send the record
//Which you have created.
//But when the user will inserted any record or not
//For that ,using the then Method for this
createRecord(Record).then(x=>{
//If the Record has been created it will print the value
console.log(x);
}).catch(err=>{
console.log(err); //Else it will catch the error
})
}
}
.metadeta file
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>57.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__AppPage</target>
<target>lightning__HomePage</target>
<target>lightning__RecordPage</target>
<target>lightning__Tab</target>
</targets>
</LightningComponentBundle>
I want to create the Account Record ,I am not able to find out what's the problem?Can someone just help.
Inside the console it giving me an error like-->{status: 400, body: {…}, headers: {…}, ok: false, statusText: 'Bad Request', …}
body: {message: 'An error occurred while trying to update the record. Please try again.', statusCode: 400, enhancedErrorType: 'RecordError', output: {…}}
errorType: "fetchResponse"
headers: {}
ok: false
status: 400
statusText: "Bad Request"
[[Prototype]]: Object
And Here is my code-->can Some one please let me know where the problem and How I can create the Account record.
Please Response with the soloution.
.html code
<template>
<!-- Form this we have created the Account record form, -->
<!-- but,Now as soon as the record the user will be inserted should be save -->
<lightning-layout>
<lightning-layout-item size="12">
<lightning-card title="AccountRecordForm">
<lightning-input type="text" label="Name" onchange={handleName}>
</lightning-input>
<lightning-input type="text" label="Phone" onchange={handlePhone}>
</lightning-input>
<lightning-button label="Save" onclick={handleSave}>
</lightning-button>
</lightning-card>
</lightning-layout-item>
</lightning-layout>
</template>
.js
import { LightningElement,api } from 'lwc';
import { createRecord } from 'lightning/uiRecordApi';
export default class LDSFormMaking1 extends LightningElement {
//Declare the variable
Name;
Phone;
//Now I want to store the data which user will be inserted into the
//Account Name-Rahul ,Phone-->784578455 As well as for the Save button
//So that Record should be save
//Now first I want to fetch the data of the User who is inserting the data
//in the Name text box i.eName-->Rahul(I want to store the Rahul inside the Name)
//So for that make the handleName inside the html.
handleName(event)
{
//For the Name ,when the user will inserted any data
//will be inside the Name text box
//1)--> User will insert the data inside the Name
//soon ,the user will be hitting the event
//2)--> That,insert value will be inside the event
this.Name=event.target.value; //From this, the user value will be inside the Name
}
handlePhone(event)
{
this.Phone=event.target.value; //From this, the User value phone will be inside the Phone
}
handleSave()
{
//Now Inside the Save button ,When ever the user will
//Inserting the value like the Name and Phone
//Should be Save the Record into the Salesforce Org.
//1)To Create the Record -->Fetch Create Record from the Lightning/uiRecordApi.
//Now How to create the object let see,Hit on lightning/uiRecordApi
//To create Record
//I need to fetch first Fields for that
let fields={'Name':this.Name,'Phone':this.Phone};
//Now I want to fetch whole Record so for that,
let Record={'apiName':'Account','Fields':fields};
//Now I want to send the record
//createRecord(Record); //From this you can send the record
//Which you have created.
//But when the user will inserted any record or not
//For that ,using the then Method for this
createRecord(Record).then(x=>{
//If the Record has been created it will print the value
console.log(x);
}).catch(err=>{
console.log(err); //Else it will catch the error
})
}
}
.metadeta file
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>57.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__AppPage</target>
<target>lightning__HomePage</target>
<target>lightning__RecordPage</target>
<target>lightning__Tab</target>
</targets>
</LightningComponentBundle>
can u please change let Record={'apiName':'Account','Fields':fields}; to let Record={'apiName':'Account',fields};
you can check below link
https://developer.salesforce.com/docs/platform/lwc/guide/data-salesforce-write.html