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"

    <lightning-input-field field-name="Status__c" value={status}></lightning-input-field>


<lightning-button variant="brand" label="Save" onclick={handleClick}>

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) {
                        new ShowToastEvent({
                            title: 'Success',
                            message: 'Account created',
                            variant: 'success',

                console.log("result", this.message);
            .catch(error => {
                this.message = undefined;
                this.error = error;
                    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) {
        insert acc;
        return acc;

1 Answer 1


Either your code sample is incomplete, or you are not actually doing anything when your form submission succeeds.

you declared an onsuccess event named handleTestCreated however, it is not in your controller.

normally, you should be able to access the fields submitted when the form successfully submits as pointed out in the documentation


   const updatedRecord = event.detail.id;
   console.log('onsuccess: ', updatedRecord);

as you can see, in the documented sample, the submitted record id is captured and logged in the console.

Note that, when you are using this component, you dont need to create the object manually in an apex controller, the component uses the User Interface API to do this for you.

There is equally a documented sample that prevents the form submission to manually do the operation.

You must log in to answer this question.

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