My current workaround for this is to add a server side action (custom labels work in apex) that would return a map of all the custom labels used in the component and then set it as an attribute of type "Map". (You need to reference all custom labels anyway in order to include them in a managed package)
bottleneck: You have to make sure you load labels before doing anything else. If you have nested structure of your components and you load labels only once in the root component -> you have to manage loading of custom labels to insure the labels attribute is accessed only when it's populated.
Apex controller:
@AuraEnabled
public static Map<String,String> getCustomLabelMap(){
Map<String,String> customLabelMap = new Map<String, String>();
customLabelMap.put('MyCustomLabel1',Label.MyCustomLabel1);
customLabelMap.put('MyCustomLabel2',Label.MyCustomLabel2);
return customLabelMap;
}
Lightning Component:
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="LABEL" type="Map" access="private"/>
<lightning:button label="{!v.LABEL.MyCustomLabel1}" onclick="{!c.myFunction}" />
Lightning Component Controller:
({
doInit: function (component, event, helper) {
var action = component.get("c.getCustomLabelMap");
action.setCallback(this, function (response) {
var LABEL = response.getReturnValue();
component.set("v.LABEL",LABEL);
});
$A.enqueueAction(action);
},
myFunction: function () {
//myFunction
}
})
Don't worry about coding defensively against your client's configuration; they're allowed to ignore certain types of test failures. This is noted in the documentation:
If a subscriber creates a validation rule, required field, or trigger on an object referenced by your package, your test might fail if it performs DML on this object. If this object is created only for testing purposes and never at runtime, and the creation fails due to these conflicts, you might be safe to ignore the error and continue the test. Otherwise, contact the customer and determine the impact.
The most important thing is that your code does not fail unit tests during upload, including code coverage. This is the only time you need to fix your code.
Best Answer
As of Summer 14, there are 2 new objects which allow you to use SOQL to see which users are licensed for particular Managed Packages:
PackageLicense
andUserPackageLicense
.UserPackageLicense
lets you see which users are licensed for a particular package:The
UserPackageLicense
object supports DML as well, so you could add triggers on User after insert/update that either assign available licenses on User activation or revoke licenses on User deactivation.The
PackageLicense
object lets you see the stats on the number of licensed users available and currently in use in your org for a particular package, as well as when the app was installed and when it expires: