0

I was trying to make a record edit form in lwc needed information from the layout of the object.

Wanted to know if this functionality is present in lwx.

0

record-edit-form itself will give you the information of layout depending on record-type-id. You should use onload event to get it.

Sample component:

HTML:

<lightning-record-edit-form object-api-name="Account"
                                onload={handleLoad}
                                record-type-id="0120K000000TO5KQAW">
        <lightning-messages>
        </lightning-messages>
        <lightning-input-field field-name="Name">
        </lightning-input-field>
    </lightning-record-edit-form>

JS:

handleLoad(event) {
    console.log('Layout => ', JSON.stringify(event.detail.layout));
}

You will get JSON as below:

enter image description here

Full JSON:

{
  "id": "00h28000002gAyyAAE",
  "layoutType": "Full",
  "mode": "Create",
  "sections": [
    {
      "collapsible": false,
      "columns": 2,
      "heading": "Account Information",
      "id": "01B28000008GeZ3EAK",
      "layoutRows": [
        {
          "layoutItems": [
            {
              "editableForNew": false,
              "editableForUpdate": false,
              "label": "Account Owner",
              "layoutComponents": [
                {
                  "apiName": "OwnerId",
                  "componentType": "Field",
                  "label": "Owner ID"
                }
              ],
              "lookupIdApiName": "OwnerId",
              "required": false,
              "sortable": false
            },
            {
              "editableForNew": false,
              "editableForUpdate": false,
              "label": "Account Record Type",
              "layoutComponents": [
                {
                  "apiName": "RecordTypeId",
                  "componentType": "Field",
                  "label": "Record Type ID"
                }
              ],
              "lookupIdApiName": "RecordTypeId",
              "required": false,
              "sortable": false
            }
          ]
        },
        {
          "layoutItems": [
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "Account Name",
              "layoutComponents": [
                {
                  "apiName": "Name",
                  "componentType": "Field",
                  "label": "Account Name"
                }
              ],
              "lookupIdApiName": "Id",
              "required": true,
              "sortable": false
            },
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "Active",
              "layoutComponents": [
                {
                  "apiName": "Active__c",
                  "componentType": "Field",
                  "label": "Active"
                }
              ],
              "lookupIdApiName": null,
              "required": true,
              "sortable": false
            }
          ]
        },
        {
          "layoutItems": [
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "Parent Account",
              "layoutComponents": [
                {
                  "apiName": "ParentId",
                  "componentType": "Field",
                  "label": "Parent Account ID"
                }
              ],
              "lookupIdApiName": "ParentId",
              "required": false,
              "sortable": false
            },
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "Upsell Opportunity",
              "layoutComponents": [
                {
                  "apiName": "UpsellOpportunity__c",
                  "componentType": "Field",
                  "label": "Upsell Opportunity"
                }
              ],
              "lookupIdApiName": null,
              "required": false,
              "sortable": false
            }
          ]
        },
        {
          "layoutItems": [
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "Account Number",
              "layoutComponents": [
                {
                  "apiName": "AccountNumber",
                  "componentType": "Field",
                  "label": "Account Number"
                }
              ],
              "lookupIdApiName": null,
              "required": false,
              "sortable": false
            },
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "Type",
              "layoutComponents": [
                {
                  "apiName": "Type",
                  "componentType": "Field",
                  "label": "Account Type"
                }
              ],
              "lookupIdApiName": null,
              "required": false,
              "sortable": false
            }
          ]
        },
        {
          "layoutItems": [
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "Account Site",
              "layoutComponents": [
                {
                  "apiName": "Site",
                  "componentType": "Field",
                  "label": "Account Site"
                }
              ],
              "lookupIdApiName": null,
              "required": false,
              "sortable": false
            },
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "Rating",
              "layoutComponents": [
                {
                  "apiName": "Rating",
                  "componentType": "Field",
                  "label": "Account Rating"
                }
              ],
              "lookupIdApiName": null,
              "required": false,
              "sortable": false
            }
          ]
        },
        {
          "layoutItems": [
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "Industry",
              "layoutComponents": [
                {
                  "apiName": "Industry",
                  "componentType": "Field",
                  "label": "Industry"
                }
              ],
              "lookupIdApiName": null,
              "required": false,
              "sortable": false
            },
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "Phone",
              "layoutComponents": [
                {
                  "apiName": "Phone",
                  "componentType": "Field",
                  "label": "Account Phone"
                }
              ],
              "lookupIdApiName": null,
              "required": false,
              "sortable": false
            }
          ]
        },
        {
          "layoutItems": [
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "SIC Code",
              "layoutComponents": [
                {
                  "apiName": "Sic",
                  "componentType": "Field",
                  "label": "SIC Code"
                }
              ],
              "lookupIdApiName": null,
              "required": false,
              "sortable": false
            },
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "Fax",
              "layoutComponents": [
                {
                  "apiName": "Fax",
                  "componentType": "Field",
                  "label": "Account Fax"
                }
              ],
              "lookupIdApiName": null,
              "required": false,
              "sortable": false
            }
          ]
        },
        {
          "layoutItems": [
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "Annual Revenue",
              "layoutComponents": [
                {
                  "apiName": "AnnualRevenue",
                  "componentType": "Field",
                  "label": "Annual Revenue"
                }
              ],
              "lookupIdApiName": null,
              "required": false,
              "sortable": false
            },
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "Website",
              "layoutComponents": [
                {
                  "apiName": "Website",
                  "componentType": "Field",
                  "label": "Website"
                }
              ],
              "lookupIdApiName": null,
              "required": false,
              "sortable": false
            }
          ]
        },
        {
          "layoutItems": [
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "Employees",
              "layoutComponents": [
                {
                  "apiName": "NumberOfEmployees",
                  "componentType": "Field",
                  "label": "Employees"
                }
              ],
              "lookupIdApiName": null,
              "required": false,
              "sortable": false
            },
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "Ticker Symbol",
              "layoutComponents": [
                {
                  "apiName": "TickerSymbol",
                  "componentType": "Field",
                  "label": "Ticker Symbol"
                }
              ],
              "lookupIdApiName": null,
              "required": false,
              "sortable": false
            }
          ]
        },
        {
          "layoutItems": [
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "POC Datetime",
              "layoutComponents": [
                {
                  "apiName": "POC_Datetime__c",
                  "componentType": "Field",
                  "label": "POC Datetime"
                }
              ],
              "lookupIdApiName": null,
              "required": false,
              "sortable": false
            },
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "Ownership",
              "layoutComponents": [
                {
                  "apiName": "Ownership",
                  "componentType": "Field",
                  "label": "Ownership"
                }
              ],
              "lookupIdApiName": null,
              "required": false,
              "sortable": false
            }
          ]
        },
        {
          "layoutItems": [
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "Acc Location",
              "layoutComponents": [
                {
                  "apiName": "Acc_Location__Latitude__s",
                  "componentType": "Field",
                  "label": "Acc Location (Latitude)"
                },
                {
                  "apiName": "Acc_Location__Longitude__s",
                  "componentType": "Field",
                  "label": "Acc Location (Longitude)"
                }
              ],
              "lookupIdApiName": null,
              "required": false,
              "sortable": false
            },
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "Number of Locations",
              "layoutComponents": [
                {
                  "apiName": "NumberofLocations__c",
                  "componentType": "Field",
                  "label": "Number of Locations"
                }
              ],
              "lookupIdApiName": null,
              "required": false,
              "sortable": false
            }
          ]
        },
        {
          "layoutItems": [
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "Test Object",
              "layoutComponents": [
                {
                  "apiName": "Test_Object__c",
                  "componentType": "Field",
                  "label": "Test Object"
                }
              ],
              "lookupIdApiName": "Id",
              "required": false,
              "sortable": false
            },
            {
              "editableForNew": false,
              "editableForUpdate": false,
              "label": "",
              "layoutComponents": [
                {
                  "apiName": null,
                  "componentType": "EmptySpace"
                }
              ],
              "lookupIdApiName": null,
              "required": false,
              "sortable": false
            }
          ]
        }
      ],
      "rows": 12,
      "useHeading": true
    },
    {
      "collapsible": false,
      "columns": 2,
      "heading": "Address Information",
      "id": "01B28000008GeZ7EAK",
      "layoutRows": [
        {
          "layoutItems": [
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "Billing Address",
              "layoutComponents": [
                {
                  "apiName": "BillingStreet",
                  "componentType": "Field",
                  "label": "Billing Street"
                },
                {
                  "apiName": "BillingCity",
                  "componentType": "Field",
                  "label": "Billing City"
                },
                {
                  "apiName": "BillingPostalCode",
                  "componentType": "Field",
                  "label": "Billing Zip/Postal Code"
                },
                {
                  "apiName": "BillingState",
                  "componentType": "Field",
                  "label": "Billing State/Province"
                },
                {
                  "apiName": "BillingCountry",
                  "componentType": "Field",
                  "label": "Billing Country"
                }
              ],
              "lookupIdApiName": null,
              "required": false,
              "sortable": false
            },
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "Shipping Address",
              "layoutComponents": [
                {
                  "apiName": "ShippingStreet",
                  "componentType": "Field",
                  "label": "Shipping Street"
                },
                {
                  "apiName": "ShippingCity",
                  "componentType": "Field",
                  "label": "Shipping City"
                },
                {
                  "apiName": "ShippingPostalCode",
                  "componentType": "Field",
                  "label": "Shipping Zip/Postal Code"
                },
                {
                  "apiName": "ShippingState",
                  "componentType": "Field",
                  "label": "Shipping State/Province"
                },
                {
                  "apiName": "ShippingCountry",
                  "componentType": "Field",
                  "label": "Shipping Country"
                }
              ],
              "lookupIdApiName": null,
              "required": false,
              "sortable": false
            }
          ]
        }
      ],
      "rows": 1,
      "useHeading": true
    },
    {
      "collapsible": false,
      "columns": 2,
      "heading": "Additional Information",
      "id": "01B28000008GeZ6EAK",
      "layoutRows": [
        {
          "layoutItems": [
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "Customer Priority",
              "layoutComponents": [
                {
                  "apiName": "CustomerPriority__c",
                  "componentType": "Field",
                  "label": "Customer Priority"
                }
              ],
              "lookupIdApiName": null,
              "required": false,
              "sortable": false
            },
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "SLA",
              "layoutComponents": [
                {
                  "apiName": "SLA__c",
                  "componentType": "Field",
                  "label": "SLA"
                }
              ],
              "lookupIdApiName": null,
              "required": true,
              "sortable": false
            }
          ]
        },
        {
          "layoutItems": [
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "SLA Expiration Date",
              "layoutComponents": [
                {
                  "apiName": "SLAExpirationDate__c",
                  "componentType": "Field",
                  "label": "SLA Expiration Date"
                }
              ],
              "lookupIdApiName": null,
              "required": true,
              "sortable": false
            },
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "SLA Serial Number",
              "layoutComponents": [
                {
                  "apiName": "SLASerialNumber__c",
                  "componentType": "Field",
                  "label": "SLA Serial Number"
                }
              ],
              "lookupIdApiName": null,
              "required": true,
              "sortable": false
            }
          ]
        }
      ],
      "rows": 2,
      "useHeading": true
    },
    {
      "collapsible": false,
      "columns": 1,
      "heading": "Description Information",
      "id": "01B28000008GeZ8EAK",
      "layoutRows": [
        {
          "layoutItems": [
            {
              "editableForNew": true,
              "editableForUpdate": true,
              "label": "Description",
              "layoutComponents": [
                {
                  "apiName": "Description",
                  "componentType": "Field",
                  "label": "Account Description"
                }
              ],
              "lookupIdApiName": null,
              "required": false,
              "sortable": false
            }
          ]
        }
      ],
      "rows": 1,
      "useHeading": true
    }
  ]
}
  • 1
    According to your comment the layout level required fields should also be shown required by lightning-record-form then ? – user70147 Sep 12 at 7:15
  • 1
    I mean when we use the lightning-record-form the form that pops up does not respect the layout level required fields – user70147 Sep 12 at 7:24
  • You are right, it might be bug – salesforce-sas Sep 12 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.