<aside> πŸ‘‰ Please review this page recordId and objectApiName special properties and Accessing Data with LWC, which are the basics for understanding this LWC.

</aside>

Introduction

The main concept included in this recipe is creating a record by using several wire adapters from the lightning/uiRecordApi module.

<aside> πŸ’‘ I strongly recommend that you follow the official documentation, starting at this page while reading this.

</aside>

Before you look at the code, I also recommend changing a value or the Account/AreaNumber field, so this will help you understand the goal of this LWC:

  1. Go to the Account object and modify the default value for the Area Numberfield, from 1000 to 555, as shown in the image bellow.
  2. Doing this, you will better understand what is the purpose of the adapters used.

Untitled

<aside> πŸ“ You can find this LWC in this relative path: force-app\\main\\default\\lwc\\ldsCreateRecord\\ldsGenerateRecordInputForCreate

</aside>

Template file

The template uses the initialisations carried in the Javascript file:

...	
	<template lwc:if={recordInput}>
        <lightning-input
            label="Name"
            onchange={handleFieldChange}
            data-field-name={nameField}
        ></lightning-input>
        <template lwc:if={areaNumberCreateable}>
            <lightning-input
                type="number"
                label="Area Number"
                onchange={handleFieldChange}
                data-field-name={areaNumberField}
                value={areaNumber}
            ></lightning-input>
        </template>
        <div class="slds-var-m-top_x-small">
            <lightning-button
                label="Create Account"
                variant="brand"
                onclick={createAccount}
            ></lightning-button>
        </div>
    </template>
    <template lwc:elseif={error}>
        <c-error-panel errors={error}></c-error-panel>
    </template>
...

Jvascript file

As the goal in this recipe is creating an Account record, so for this we should use the createRecordwire adapter. This adapter requires a recordInputparameter which type is RecordInput.

This parameter can be created manually as we did in the previous recipe: LWC LdsCreateRecord but this is not ideal, as you miss important information as the default record values and the accessibility related to the fields (are all of them creatable?).

So, the preferred option is to use another wire adapter, the generateRecordInputForCreate(record, objectInfo):