[SalesForce] Namespace in lightning component

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.

Best Answer

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 .

Related Topic