addAccount.html
<template>
<lightning-card title="Create your Account">
<p class="slds-p-horizontal_small">
<lightning-record-edit-form
object-api-name="Account"
onsuccess={handleSuccess}>
<lightning-input-field field-name="Name" name="name">
</lightning-input-field>
</lightning-record-edit-form>
</p>
<p slot="footer">
<lightning-button
type="submit"
name="submit"
label="Create Account"
onclick={handleClick}>
</lightning-button>
</p>
</lightning-card>
</template>
addAccount.js
import { LightningElement, track, api, wire } from 'lwc';
import insertNewAccount from '@salesforce/apex/AddAccount.insertNewAccount';
export default class AddAccount extends LightningElement {
@track Name;
handleClick(event)
{
console.log(event.target.label);
var inp=this.template.querySelector("lightning-input-field");
this.Name=inp.value;
console.log(inp.value);
insertNewAccount("accountName:this.Name").then(result=>{
console.log(JSON.stringify(result));
}).catch(error=>{
console.log(error);
})
}
}
AddAccount.cls
public with sharing class AddAccount {
@AuraEnabled
public static Account insertNewAccount(String accountName){
Account newAccount = new Account();
newAccount.Name = accountName;
insert newAccount;
return newAccount;
}
}
Please help with passing the paramenter
Hi Sukriti,Please use below code:- addAccount.js
if you need any assistanse, Please let me know!!Kindly mark my solution as the best answer if it helps you.ThanksMukeshimport { LightningElement, track, api, wire } from 'lwc';
import insertNewAccount from '@salesforce/apex/AddAccount.insertNewAccount';
export default class AddAccount extends LightningElement {
@track Name;
handleClick(event)
{
console.log(event.target.label);
var inp=this.template.querySelector("lightning-input-field");
this.Name=inp.value;
console.log(inp.value);
insertNewAccount({accountName:this.Name}).then(result=>{
console.log(JSON.stringify(result));
}).catch(error=>{
console.log(error);
})
}
}