Tweeted twitter.com/StackSalesforce/status/935959654894579713
2 deleted 46 characters in body
source | link

Background

We are developing an app where we use lightning components.

Issue

When are trying to package the components, package manager returns an error referencing to some custom fields that are not found in the package. This is because when we created the namespace, it added a prefix in every custom metadata.

Workarounds

  1. Put the prefix in every custom fields and object in the component, controller and helper code.
  2. Get the prefix from a custom metadata type and build dynamically the metadata names. It works fine for the Component Controller and Helper. But we cannot set the prefix dynamically in the component page.

Expected workaround We

We want to get the prefix from a custom metadata type because we have several environments and it change between them. So we can discard the 1st workaround. Then

Then, if we want to use custom fields dynamically in the component, we think that the only way is to use a DTO class in the controller. This solution would take a lot of time and we want to verify is there is another option to accomplish the solution. 

What is the best practice to use the prefix namespace in Lightning Components?

Code Samples

<!-- parentComponet.cmp -->
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId" controller="ExampleHelper" access="global">
<aura:handler name="init" action="{!c.doInit}" value="{!this}" />
...
<aura:attribute name="prefix" type="String" access="private" default="prefix__" />
...
<c:child_1 aura:id="child_1" prefix="{!v.prefix}" settingExample="..." />
<c:child_2 aura:id="child_2" prefix="{!v.prefix}" objectExample="..." />
...
</aura:component>

<!-- parentComponentController.js -->
({
   doInit: function(cmp, event, helper){
    helper.getPrefix();
   ...
   },
   ...
})
<!-- parentComponentHelper.js -->
({
 getPrefix: function(){
   ...
   action.getCall...
   ...
   cmp.set('v.prefix', e.getReturnValue());
 });
})

-- COMPONENT CHILD --
<!-- child_1.cmp -->
<aura:component>
    <aura:attribute name="prefix" type="String" access="global" />
    <aura:attribute name="settingExample" type="Object" access="global" />
    {!v.settingExample.nameExample__c} //NOT VALID WITH PREFIX
    {!v.settingExample.[prefix]+'.'+nameExample__c} //NOT WORKING
</aura:component>

Background

We are developing an app where we use lightning components.

Issue

When are trying to package the components, package manager returns an error referencing to some custom fields that are not found in the package. This is because when we created the namespace, it added a prefix in every custom metadata.

Workarounds

  1. Put the prefix in every custom fields and object in the component, controller and helper code.
  2. Get the prefix from a custom metadata type and build dynamically the metadata names. It works fine for the Component Controller and Helper. But we cannot set the prefix dynamically in the component page.

Expected workaround We want to get the prefix from a custom metadata type because we have several environments and it change between them. So we can discard the 1st workaround. Then, if we want to use custom fields dynamically in the component, we think that the only way is to use a DTO class in the controller. This solution would take a lot of time and we want to verify is there is another option to accomplish the solution.

Code Samples

<!-- parentComponet.cmp -->
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId" controller="ExampleHelper" access="global">
<aura:handler name="init" action="{!c.doInit}" value="{!this}" />
...
<aura:attribute name="prefix" type="String" access="private" default="prefix__" />
...
<c:child_1 aura:id="child_1" prefix="{!v.prefix}" settingExample="..." />
<c:child_2 aura:id="child_2" prefix="{!v.prefix}" objectExample="..." />
...
</aura:component>

<!-- parentComponentController.js -->
({
   doInit: function(cmp, event, helper){
    helper.getPrefix();
   ...
   },
   ...
})
<!-- parentComponentHelper.js -->
({
 getPrefix: function(){
   ...
   action.getCall...
   ...
   cmp.set('v.prefix', e.getReturnValue());
 });
})

-- COMPONENT CHILD --
<!-- child_1.cmp -->
<aura:component>
    <aura:attribute name="prefix" type="String" access="global" />
    <aura:attribute name="settingExample" type="Object" access="global" />
    {!v.settingExample.nameExample__c} //NOT VALID WITH PREFIX
    {!v.settingExample.[prefix]+'.'+nameExample__c} //NOT WORKING
</aura:component>

Background

We are developing an app where we use lightning components.

Issue

When are trying to package the components, package manager returns an error referencing to some custom fields that are not found in the package. This is because when we created the namespace, it added a prefix in every custom metadata.

Workarounds

  1. Put the prefix in every custom fields and object in the component, controller and helper code.
  2. Get the prefix from a custom metadata type and build dynamically the metadata names. It works fine for the Component Controller and Helper. But we cannot set the prefix dynamically in the component page.

Expected workaround

We want to get the prefix from a custom metadata type because we have several environments and it change between them. So we can discard the 1st workaround.

Then, if we want to use custom fields dynamically in the component, we think that the only way is to use a DTO class in the controller. 

What is the best practice to use the prefix namespace in Lightning Components?

Code Samples

<!-- parentComponet.cmp -->
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId" controller="ExampleHelper" access="global">
<aura:handler name="init" action="{!c.doInit}" value="{!this}" />
...
<aura:attribute name="prefix" type="String" access="private" default="prefix__" />
...
<c:child_1 aura:id="child_1" prefix="{!v.prefix}" settingExample="..." />
<c:child_2 aura:id="child_2" prefix="{!v.prefix}" objectExample="..." />
...
</aura:component>

<!-- parentComponentController.js -->
({
   doInit: function(cmp, event, helper){
    helper.getPrefix();
   ...
   },
   ...
})
<!-- parentComponentHelper.js -->
({
 getPrefix: function(){
   ...
   action.getCall...
   ...
   cmp.set('v.prefix', e.getReturnValue());
 });
})

-- COMPONENT CHILD --
<!-- child_1.cmp -->
<aura:component>
    <aura:attribute name="prefix" type="String" access="global" />
    <aura:attribute name="settingExample" type="Object" access="global" />
    {!v.settingExample.nameExample__c} //NOT VALID WITH PREFIX
    {!v.settingExample.[prefix]+'.'+nameExample__c} //NOT WORKING
</aura:component>
1
source | link

Lightning Components in Managed Package

Background

We are developing an app where we use lightning components.

Issue

When are trying to package the components, package manager returns an error referencing to some custom fields that are not found in the package. This is because when we created the namespace, it added a prefix in every custom metadata.

Workarounds

  1. Put the prefix in every custom fields and object in the component, controller and helper code.
  2. Get the prefix from a custom metadata type and build dynamically the metadata names. It works fine for the Component Controller and Helper. But we cannot set the prefix dynamically in the component page.

Expected workaround We want to get the prefix from a custom metadata type because we have several environments and it change between them. So we can discard the 1st workaround. Then, if we want to use custom fields dynamically in the component, we think that the only way is to use a DTO class in the controller. This solution would take a lot of time and we want to verify is there is another option to accomplish the solution.

Code Samples

<!-- parentComponet.cmp -->
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId" controller="ExampleHelper" access="global">
<aura:handler name="init" action="{!c.doInit}" value="{!this}" />
...
<aura:attribute name="prefix" type="String" access="private" default="prefix__" />
...
<c:child_1 aura:id="child_1" prefix="{!v.prefix}" settingExample="..." />
<c:child_2 aura:id="child_2" prefix="{!v.prefix}" objectExample="..." />
...
</aura:component>

<!-- parentComponentController.js -->
({
   doInit: function(cmp, event, helper){
    helper.getPrefix();
   ...
   },
   ...
})
<!-- parentComponentHelper.js -->
({
 getPrefix: function(){
   ...
   action.getCall...
   ...
   cmp.set('v.prefix', e.getReturnValue());
 });
})

-- COMPONENT CHILD --
<!-- child_1.cmp -->
<aura:component>
    <aura:attribute name="prefix" type="String" access="global" />
    <aura:attribute name="settingExample" type="Object" access="global" />
    {!v.settingExample.nameExample__c} //NOT VALID WITH PREFIX
    {!v.settingExample.[prefix]+'.'+nameExample__c} //NOT WORKING
</aura:component>