1

I have a custom lightning-record-edit-form component that looks like this:

<lightning-record-edit-form 
    record-id={id} 
    record-type-id={recordTypeId} 
    object-api-name="Account" 
    density="comfy"
    onsuccess={handleSuccess} 
    onsubmit={handleSubmit} 
    onerror={handleError}>
        
    <lightning-messages></lightning-messages>

    <lightning-input-field field-name="Name" required="true">
    <lightning-input-field field-name="Ownership" required="true">

    <template if:true={isPublicEntity}>
        <lightning-input-field field-name="AnnualRevenue">
        <lightning-input-field field-name="DunsNumber">
    </template>

    <lightning-input-field field-name="Website" required="true">
    <lightning-input-field field-name="Phone" required="true">

    <hr />
    <div class="slds-grid slds-grid_align-end">
        <div class="slds-col">
            <lightning-button class="slds-m-top_small" variant="brand" type="submit" label="Save"></lightning-button>
        </div>
    </div>

</lightning-record-edit-form>

This component is nested inside a parent component that holds a list of Accounts. When the success event fires I have my parent component capture the event to add the Name, Id, and Ownership to the list. This works for one of my Account record types, but not for another. The Ownership field is missing from the success event. An example of the event, which includes many fields but distinctly missing the one I want:

{
  "apiName": "Associated_Individual_Company__c",
  "childRelationships": {},
  "id": "a0GK00000000000001",
  "lastModifiedById": "0054x0000000000001",
  "lastModifiedDate": "2021-01-23T16:47:27.000Z",
  "recordTypeId": "012K0000000MSYhIAO",
  "recordTypeInfo": {
    "available": true,
    "defaultRecordTypeMapping": false,
    "master": false,
    "name": "Standard Company",
    "recordTypeId": "012K0000000MSYhIAO"
  },
  "systemModstamp": "2021-01-23T16:47:27.000Z",
  "fields": {
    "AnnualRevenue": {
        "displayValue": "$1,234,567.57",
        "value": "1234567.57"
    },
    "CreatedBy": {
      "displayValue": "Malachi Constant",
      "value": {
        "apiName": "User",
        "childRelationships": {},
        "id": "0054x0000000000000",
        "lastModifiedById": "0054x0000000000000",
        "lastModifiedDate": "2021-01-23T05:15:42.000Z",
        "recordTypeId": null,
        "recordTypeInfo": null,
        "systemModstamp": "2021-01-23T05:15:42.000Z",
        "fields": {
          "Id": {
            "displayValue": null,
            "value": "0054x0000000000000"
          },
          "Name": {
            "displayValue": null,
            "value": "Malachi Constant"
          }
        }
      }
    },
    "CreatedById": {
      "displayValue": null,
      "value": "0054x0000000000000"
    },
    "CreatedDate": {
      "displayValue": "1/23/2021, 11:47 AM",
      "value": "2021-01-23T16:47:27.000Z"
    },
    "Description__c": {
      "displayValue": null,
      "value": "All about the Account"
    },
    "LastModifiedBy": {
      "displayValue": "Malachi Constant",
      "value": {
        "apiName": "User",
        "childRelationships": {},
        "id": "0054x0000000000000",
        "lastModifiedById": "0054x0000000000000",
        "lastModifiedDate": "2021-01-23T05:15:42.000Z",
        "recordTypeId": null,
        "recordTypeInfo": null,
        "systemModstamp": "2021-01-23T05:15:42.000Z",
        "fields": {
          "Id": {
            "displayValue": null,
            "value": "0054x0000000000000"
          },
          "Name": {
            "displayValue": null,
            "value": "Malachi Constant"
          }
        }
      }
    },
    "LastModifiedById": {
      "displayValue": null,
      "value": "0054x0000000000000"
    },
    "LastModifiedDate": {
      "displayValue": "1/23/2021, 11:47 AM",
      "value": "2021-01-23T16:47:27.000Z"
    },
    "Name": {
      "displayValue": null,
      "value": "Acme Corp."
    },
    "Owner": {
      "displayValue": "Winston Niles Rumfoord",
      "value": {
        "apiName": "Name",
        "childRelationships": {},
        "id": "0054x0000000000000",
        "lastModifiedById": null,
        "lastModifiedDate": null,
        "recordTypeId": null,
        "recordTypeInfo": null,
        "systemModstamp": null,
        "fields": {
          "Id": {
            "displayValue": null,
            "value": "0054x0000000000000"
          },
          "Name": {
            "displayValue": null,
            "value": "Winston Niles Rumfoord"
          }
        }
      }
    },
    "OwnerId": {
      "displayValue": null,
      "value": "0054x0000000000000"
    },
    "Phone": {
      "displayValue": "(555) 555-5555",
      "value": "(555) 555-5555"
    },
    "RecordType": {
      "displayValue": "Standard Company",
      "value": {
        "apiName": "RecordType",
        "childRelationships": {},
        "id": "012K0000000MSYhIAO",
        "lastModifiedById": "0054x0000000000000",
        "lastModifiedDate": "2021-01-12T23:13:01.000Z",
        "recordTypeId": null,
        "recordTypeInfo": null,
        "systemModstamp": "2021-01-12T23:13:01.000Z",
        "fields": {
          "Id": {
            "displayValue": null,
            "value": "012K00000000000000"
          },
          "Name": {
            "displayValue": "Standard Company",
            "value": "Standard Company"
          }
        }
      }
    },
    "RecordTypeId": {
      "displayValue": null,
      "value": "012K00000000000000"
    },
    "Website": {
        "displayValue": "https://salesforce.stackexchange.com/",
        "value": "https://salesforce.stackexchange.com/"
    }
  }
}

Why doesn't the success event return a field value that I just saved within the lightning-record-edit-form?

3

This tripped me for a good while. The success event is returned from the User Interface API (specifically a Record event) after the request from the component is saved. This has the benefit of allowing the values from formulas and automated processes to come back in the response. The key thing that I was missing was that the UI API response only contains the fields that are on the Layout for the given object Record Type and Profile combination. It doesn't matter what fields I include inside lightning-record-edit-form. The form will display the fields so long as field level security allows them, but once the component sends the data to the server the response comes back in the form of the record layout the user would see in a standard component.

After adding the Ownership field to the Layout that was assigned to the "Standard Company" record type, it was included in the response back.

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.