abhi saxena
abhi saxena

Reputation: 1

How to Update RecordTypeId field in Lightning record form in salesforce?

Hi @all I have lightning record edit form which are showing specific value one of them is a recordtype. I want to update the recordtype from the same as other fields are updating but when I click on recordtype field it shows me the below error:- [LWC component's @wire target property or method threw an error during value provisioning. Original error: [Field: RecordTypeId is not a valid lookup field.]]

Upvotes: 0

Views: 4104

Answers (1)

eyescream
eyescream

Reputation: 19622

Record Type change is a critical operation that messes everything up. Potentially you're looking at new page layout (incl required/readonly fields), new picklist dependencies... There's reason why you select it first before any layout is displayed. And why record type change is a special button, not a field visible on normal edit action.

If you know what you're doing, are confident the requirements won't change / you'll know how to represent the changed layouts, picklists etc...

  1. Use getObjectInfo to pull (among others) the Map of record types.
  2. Use this data to build lightning-combobox that onchange updates a helper variable (you'd ideally have that variable bound to <lightning-record-edit-form record-id={recordId} record-type-id={recordTypeId}
  3. Have a custom handleSubmit in the record-edit-form in which you'd intercept the save, prepopulate the field and then submit.

Upvotes: 0

Related Questions