1

For example, if we have 2 different record types with different page layouts.

When providing a new recordId to the lightning-record-form if the said record is of a different record type, the page layout change lags one step behind while the field values update correctly.

Example setup:

  • RecordId(A) has PageLayout(a)
  • RecordId(B) has PageLayout(b)
  • RecordId(B1) has PageLayout(b)

Resulting behaviour of lightning-record-form:

steps:
  1. pass RecordId(A) --> Displays PageLayout(a) //works well 1st time
  2. pass RecordId(B) --> Displays PageLayout(a) //still "a"! ignores record type change
  3. pass RecordId(A) --> Displays PageLayout(b) //now flipped to layout "b" but late
  4. pass RecordId(B) --> Displays PageLayout(a) //again late flip out of phase
  5. pass RecordId(B1) --> Displays PageLayout(b) //back to norm, but only because previous record was of the same record type

does anyone know whether it's a bug or some caching behaviour that can be worked around?

1 Answer 1

2

If I can reproduce this, I'll take time today to create a bug with salesforce.com regarding this matter.

Until then, the usual solution is to remove the entire component from the DOM and add it back after one render cycle. This causes a brief flicker, but is practically guaranteed to work.

showRecordForm = true
_recordId
@api set recordId(value) {
  this._recordId = value
  this.showRecordForm = false
  setTimeout(() => this.showRecordForm = true)
}
get recordId() {
  return this._recordId
}

...

<lightning-recordform if:true={showRecordForm} ...
1
  • worked like a charm, thanks Brian! Jan 31, 2022 at 13:51

You must log in to answer this question.

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