We are using force:recordData to get a custom object record to the lightning component's JS like so:


<aura:attribute name="recordFields" type="Custom_Object__c"/>
<aura:attribute name="recordLoadError" type="String"/>

<force:recordData aura:id="recordLoader"
                 fields="Name,Id,Custom_Field_1__c, Custom_Field_2__c"


var myCustomField = component.get('v.recordFields.Custom_Field_1__c');      

This of course works on our dev orgs, yet on our managed package it returns null because of namespace issues.

"No such column 'Custom_Field_1__c' exists on entity 'NAMESPACE__Custom_Object__c'."

How can I set the namespace dynamically in the component and JS to prevent these issues?

  • Welcome Ori. Am I right in assuming you're developing this inside a managed package? – Sebastian Kessel Jul 17 at 15:49
  • Yes, that's why I can't put the namespace hardcoded. – Ori Fishman Jul 21 at 6:30
  • Well... that's why you can do it.... but the answer below by sfdcfox is the right solution – Sebastian Kessel Jul 22 at 15:22

This is a situation in which you should be using Salesforce DX. Salesforce DX resolves this problem by allowing you to create scratch orgs (ephemeral developer edition orgs) that you can use for development and testing purposes. Normal developer edition orgs cannot share namespaces and cause issues with ISV development cycles, particularly in Lightning components.

  • In our VF pages we used to use '{!$ObjectType. Custom_Object__c.Fields. Custom_Field_1__c.Name}' to get the field name with or without namespace. I hoped there is a way to do this in lightning components. Thanks – Ori Fishman Jul 21 at 6:32
  • 1
    @OriFishman In Aura, no. LWC has better support foe namespaces. Either way, my answer stands: use Scratch Orgs to simplify your code and deployment processes. – sfdcfox Jul 21 at 13:28

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.