On a lightning-record-edit-form page, how you determine the field type(text, lookup, picklist)?
Thank you, P

1 Answer 1


The beauty of using the lightning-record-edit-form component is that you don't need to worry about the types of any of the fields. Using lightning-input-field inside of the component is enough - Salesforce will handle the rest and show the appropriate UI based on the type of the field. For example, a combo box for a picklist, an input[type="text"] for text, and a textarea for long text.

That said, there isn't any way in the lightning-record-edit-form component to tell what type a field is. All of the logic is handled internally to the component. Your best option is to use the uiObjectInfoApi module in your LWC and call getObjectInfo to find out information about an object. getObjectInfo will return an Object Info object which will let you access metadata on the object and its fields. Follow the pattern in the example below.

import { LightningElement, wire } from 'lwc';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import ACCOUNT_OBJECT from '@salesforce/schema/Account';

export default class Example extends LightningElement {
    @wire(getObjectInfo, { objectApiName: ACCOUNT_OBJECT })
    accountObjectInfo({data, error}) {
        if(data) {
            console.log(data.fields['Name'].dataType); //String
            console.log(data.fields['Fax'].dataType); //Phone
            console.log(data.fields['AccountSource'].dataType); //Picklist
            console.log(data.fields['NumberOfEmployees'].dataType); //Int
            // etc.

  • That really depends on your other component, but in general yes. Can you ask a new question or update your question with more clarity?
    – nbrown
    Nov 23, 2020 at 19:07
  • Thanks for the reply nbrown. I am trying to add a custom LWC to the html based on the field type.
    – Phuc
    Nov 23, 2020 at 19:07
  • I would post your code and more of an explanation of what you want to do.
    – nbrown
    Nov 23, 2020 at 19:08

You must log in to answer this question.

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