I am using below record-edit-form to create record - After button click i am getting rec object as null {}. How to pass the values from inputfields to apex.
The lightning-button is in footer of a modal and the input-field is in body of a modal.
<lightning-record-edit-form object-api-name="Test__c"
onsuccess={handleTestCreated}>
<lightning-input-field field-name="Status__c" value={status}></lightning-input-field>
</lightning-record-edit-form>
<lightning-button variant="brand" label="Save" onclick={handleClick}>
</lightning-button>
js - I am creating a object as there are many fields
**import createTest from '@salesforce/apex/TestController.createTest';
@track status;
@track rec = {
status : this.status
}
handleClick() {
createTest({ acc : this.rec })
.then(result => {
this.message = result;
this.error = undefined;
if(this.message !== undefined) {
this.dispatchEvent(
new ShowToastEvent({
title: 'Success',
message: 'Account created',
variant: 'success',
}),
);
}
console.log(JSON.stringify(result));
console.log("result", this.message);
})
.catch(error => {
this.message = undefined;
this.error = error;
this.dispatchEvent(
new ShowToastEvent({
title: 'Error creating record',
message: error.body.message,
variant: 'error',
}),
);
console.log("error", JSON.stringify(this.error));
});
}**
apex -
public static Test__c createTest(Test__c acc) {
system.debug('acc'+acc);
insert acc;
return acc;
}