We have one dev org(without namespace) and one packaging org(with namespace) for developing lightning app. We are trying to access custom field in Lightning helper method as expence__c. It works fine in dev org. But in managed package response returned from the server controller prefixes namespace to given field as namespace__expence__c.

Code tries to access field expence__c which in turn gives field undefined error.

We can't hardcode namespace in code as it won't work in dev org.

We found two solution to this.

  1. Add/Remove namespace to field depending on org in Lightning code. (not preferred)

  2. Write DTO(data transfer object) class for all objects which we wish to use in Lightning. (need to create multiple DTO classes for those objects)

What is the best way to handle given problem.

  • Can you use c__expense__c? I don't know if that would work at all, just a thought. – Kris Gray Nov 29 '16 at 6:17
  • @KrisGray sorry given solution is not working in dev org. As apex controller returns field as expence__c and js code is trying to access as c__expence__c. Thinks of it as js object where expenc__c field is key in expense object and you are trying to access key with/without prefixes. In dev org there is no prefix in key so it won't work and will throw key undefined error. – Soham Nov 29 '16 at 7:08
  • @KrisGray This is a known limitation which adds pain to adopt lightning for managed package apps . – Mohith Shrivastava Nov 29 '16 at 10:18
  • @MohithShrivastava pls check this passing-complex-structured-data-type-from-lightning-to-apex I'm getting same kind of salesforce internal error while passing wrapper class to controller. Why we need to serialize/deserialize, is this known bug? Code works fine for objects but not for classes. – Soham Nov 30 '16 at 14:28
  • Soham that's a bug as well – Mohith Shrivastava Nov 30 '16 at 14:32

Thats a current limitation of the platform .The Javascript file does not get namespace added unlike visualforce pages for managed package .

I wrote a blog post on this .

The best way would be to create a message layer or a wrapper class like your second approach and that avoids the problem .The only caveat is you end up writing bunch of classes .


Here is the full description

Component used in markup ==><yournamespace:myComponent />

Component used in a system attribute ==>

<aura:component extends="yournamespace:myComponent">

<aura:component implements="yournamespace:myInterface">
<aura:component controller="yournamespace.ExpenseController">
<aura:attribute name="expenses" type="yournamespace__Expense__c[]" />
<aura:attribute name="newExpense" type="yournamespace__Expense__c"
       default="{ 'sobjectType': 'yournamespace__Expense__c',
           'Name': '',
           'yournamespace__Amount__c': 0}" />
<aura:handler event="yournamespace:updateExpenseItem" action=… />
<aura:registerEvent type="yournamespace:updateExpenseItem" name=… />
<aura:handler event="yournamespace:updateExpenseItem" action=… />
<aura:dependency resource="markup://yournamespace:myComponent" />
<ltng:require scripts="{!$Resource.yournamespace__resourceName}" styles="{!$Resource.yournamespace__resourceName}" />


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.