1

I have a lightning-record-edit-form that includes few standard fields few custom fields. I've register onsuccess(event) function that does some stuff with the newly updated record. I'm accessing this data using the event.detail.fields object. I'm referring to the field names using their API names (imported them to the JS file). This works perfectly fine in my dev org.

When packaging this component, it stops working. When saving the record, the event.detail.fields is not filled with the custom fields I have on this object and the code crushes when I'm trying to refer to it (reminder: with the valid API names I imported). The thing is, the data is being saved and if I refresh the page, I see the edits I made for both standard and custom fields. I tried checking permissions but the user has full edit access for both objects and the custom fields.

I tried examining the event.object.fields and see what it contains and it really doesn't have my custom fields :-\ (and in my dev org, it does).

What am I missing here?

Template code:

<lightning-record-edit-form object-api-name="ServiceTerritory" record-id={Id} layout-type="Compact" onsuccess={handleSuccess}>
    <lightning-input-field field-name={apiFieldCustomFieldName}></lightning-input-field>
    <lightning-button class="slds-m-top_small" type="submit" label="Save">
    </lightning-button>
</lightning-record-edit-form>

Hand picked JS code (only relevant):

import CUSTOM_FIELD_NAME  from '@salesforce/schema/ServiceTerritory.Custom_Field__c';

apiFieldCustomFieldName = CUSTOM_FIELD_NAME.fieldApiName;

handleSuccess(e) { 

    const fields = e.detail.fields;

    // THIS WILL THROW AN ERROR ON MANAGED PACKAGE BUT NOT ON DEV
    console.log(fields[this.apiFieldCustomFieldName].value);


    // TRUE in dev org, FALSE in managed package
    console.log(fields.hasOwnProperty(this.apiFieldCustomFieldName));

}

(don't worry, everything is declared the right place of the file).

When debugging, I do see the namespace on the manage package. And again, it saves fine but the object on the onsuccess is not returned with all the fields

  • Try adding the package namespace to the fields API names on the lightning inputs, also refer the same in onsuccess. – rahul gawale May 18 at 8:41
  • 1
    @rahulgawale - I did, this why I said I imported the API names. The data loads fine and even saved fine (you can see it only after refresh). The only issue is that the onsuccess doesn't include this data on the updated record (event.detail.fields) – Shai May 18 at 8:46
  • Can you add the code here? – rahul gawale May 18 at 8:52
  • 1
    I will add the relevant stuff in few moments, thanks @rahulgawale – Shai May 18 at 9:01
  • @rahulgawale added, thanks! – Shai May 18 at 9:26
2

Well, it seems like the fields that are returned in the onsuccess events are the one that are configured in the page layout. After putting all of these fields in the layout - I get the updates in the event.detail.fields as expected.

| improve this answer | |
  • When you say on page layout, you mean referred by lighting-input-field? – rahul gawale May 18 at 12:01
  • 1
    Nope, the default page layout you have on the object manager – Shai May 18 at 12:20
  • 1
    Ohh, I got it. +1. Learned something new today. – rahul gawale May 18 at 12:23
  • 1
    Me too, spent 5+ hours on this :-\ – Shai May 18 at 15:16

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.