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
onsuccess
.