4

So in our lightning code base we usually refer to labels from js helpers and controllers as the following (it's static reference, not dynamic one):

$A.get("$Label.c.SyncTransactionDetails_EditDialog_Title")

Everything works fine. The problem appeared when we packaged all our stuff into managed package and installed it on client orgs. As it turns out, all labels referred from lightning helpers and controllers were not included into the package.

The funny think - there is no way to directly add specific label to the managed package, it relies on dependency auto-detection mechanism, which doesn't work for some reason in regards to js helpers and controllers.

The only workaround we've come up so far - add some comments/invisible sections to component's markup and mention all those labels explicitly there. But it's dozens of components and hard to maintain in the future.

Is there any better suggestions? Are we doing something wrong?

2

As SFDC platform is unable to parse lightning components to see which custom labels are used, you can create a dummy apex class where you call them to create apex dependencies ( so include them in your package ).

It is better than using invisible sections in components, as it is not adding useless weight to the client application ( and it also increases easily your testClasses code coverage ^^ )

Here is a sample of the one we use for our ISV

// ISV PACKAGED
// 
// In case custom labels are referenced only in lightning, plz add them here ( and respect alphabetical order) so they are taken during Package generation
global with sharing class DescribePackageCustomLabels {

    global static Boolean describeLabelLs()
    {
        String AccountSettings = Label.AccountSettings;
        String ActivityAbandoned = Label.ActivityAbandoned;
        String All = Label.All ;
        String AllowanceAmount = Label.AllowanceAmount;
        String Amount = Label.Amount;
        String AmountPlaceholder = Label.AmountPlaceholder;
        String AmountTooBig = Label.AmountTooBig;
        // .......
        return true ;
    }
}

Test class :

// ISV PACKAGED
// 
@isTest
private class DescribePackageCustomLabelsTest {
    static testMethod void describeLabelLsTest(){
        Boolean TestOk = DescribePackageCustomLabels.describeLabelLs();
        system.assert(TestOk == true);
    }
}

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.