[SalesForce] What namespace to use when developing Lightning components for a managed package

I have a managed package that is created from our "release org" to which the namespace has been assigned.

I have developed some Lightning components for use via Lightning Out in a Visualforce page. Whilst developing these components, all was well using the "c" placeholder namespace prefix. All was also well when adding these components to the managed package and uploading it.

However, when I install the package on an org and try to access the Visualforce pages that use these components, the pages fail to render completely (the parts of the page using the lightning components are missing) and shows a "server side error" message in the bottom left corner.

The Visualforce page uses pretty much the boilerplate 3 step integration:

  1. Add apex:includeLightning to the page
  2. Insert a placeholder element(s) for the component(s) in the page structure
  3. Use the Lightning App (referencing the key components) in the page and explicitly create the component(s) required

My dev org has this like:

<apex:page ...>
    <apex:includeLightning/>
    <script>
        $Lightning.use("c:myLightningApp", function() {
            $Lightning.createComponent("c:filter",
                {},
                "lightning",
                function(component) {
                });
        });
    </script>
    ...
    <div id="lightning"/>
    ...
</apex:page>

I find this works fine on the dev org (no namespace) and I can successfully deploy this to my release org (with namespace) where I build the package.

The issue is that the "c:" namespace prefix for the lightning app is not recognized on an org where the package is installed, so the page fails to load.

I have tried updating the component/app references on my dev org to use the namespace for my release org, but I cannot – the namespaces doesn't exist and so the updates cannot be deployed.

Without switching to SalesforceDX, can anyone suggest what I can do to enable me to build, package and install my lightning components so they will actually work in my dev org, my release org and in the package installed on a customer org?

Best Answer

When using Salesforce DX, you register your namespace with the Dev Hub. From there, you can create Scratch Orgs that use the namespace by using the namespace attribute in your scratch org definition file. At this point, you will always use your namespace instead of c to reference your components.

Related Topic