0

I am trying to add some default values for some field for lightning-record-form in lightning web component in salesforce.

I have search through the web and found something like this.

<lightning-record-form
    object-api-name={objectApiName}
    fields={fields}
    record-type-id={recordTypeId}
>
</lightning-record-form>

Where fields are represented in the controller like this,|

fields = [NAME_FIELD, ACCOUNT_FIELD];

or

fields = [
    { fieldApiName: 'Name', objectApiName: 'Custom_Object__c' },
    { fieldApiName: 'Account__c', objectApiName: 'Custom_Object__c'}
];

both works fine if I don't need any predefined value. I am trying to add predefined value using the fields representation syntax like,

fields = [
    { fieldApiName: 'Name', objectApiName: 'Custom_Object__c', value: 'Sample Name' },
    { fieldApiName: 'Account__c', objectApiName: 'Custom_Object__c', value: '0XXXXXXXXXXXXXXQAF'}
];

Default value is not setting.I don't know if I am using the proper way or not, or there could be another way. Please someone help me with this?

Note: I know that I can use lightning-record-edit-form and lightning-input-field to full fill my requirements. In this way I have to add every field using lightning-input-field which I don't want.

Thanks in advance.

1 Answer 1

0

As per the documentation,

Prepopulating Field Values

lightning-record-form does not support prepopulating of field values when the form loads. To create a form that displays custom field values, use the lightning-record-edit-form component.

1
  • I know about lightning-record-edit-form, was looking solutions for lightning-record-form. Thanks for the reply.
    – Ripon
    Commented Aug 11, 2023 at 12:10

You must log in to answer this question.

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