function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mikechayesmikechayes 

SFDX - Namespace issues working with Scratch Org and a managed package.

Summary
I work on a managed package that has been around for some time now.  I am in the process of moving our development team to scratch orgs with VS Code.  However, our namespace does not appear to be moving correctly from the Packaging org or into the Scratch org.

Here are my steps
  • From within VS Code I execute “SFDX: Create Project”
  • I updated the project-scratch-def.json and sfdx-project.json files.
project-scratch-def.json
{
  "orgName": "Scratch Org",
  "edition": "Developer",
  "release": "",
  "adminEmail": "mike@mike.com",
  "features": [],
  "namespace": "WAVY"
}
sfdx-project.json
{
  "packageDirectories": [
    {
      "path": "force-app",
      "default": true
    }
  ],
  "namespace": "WAVY",
  "sfdcLoginUrl": "https://login.salesforce.com",
  "sourceApiVersion": "47.0"
}
  • From within VS Code I execute “SFDX: Create a Default Scratch Org…”
  • I confirm the namespace is in the Scratch org with “SELECT NamespacePrefix FROM Organization”.
  • I retrieve the metadata from the managed package with:
sfdx force:mdapi:retrieve -s -r ./mdapipkg -u mike@mail.com -p WAVYPackage
  • I unzip unpackaged.zip and convert with:
sfdx force:mdapi:convert --rootdir  ./mdapipkg
 
  • I review the code Lightning component file. The namespace is removed from all sobjectType in the Scratch org.
<aura:attribute name="Batch" type="Batch__c" access="GLOBAL" default="{ sobjectType: 'Batch__c' }" />  
<force:inputField aura:id="hiddenLookup" value="{!v.Batch.WAVY__DefaultChartofAccounts__c}" class="slds-hide" />
  • In the Packaging org this same code looks like:
<aura:attribute name="Batch" type="WAVY__Batch__c" access="GLOBAL" default="{ sobjectType: 'WAVY__Batch__c' }" />  
<force:inputField aura:id="hiddenLookup" value="{!v.Batch.WAVY__DefaultChartofAccounts__c}" class="slds-hide" />
  • When the lightning page is executed in the Scratch org I get the following error:
aura://ComponentController: org.auraframework.throwable.AuraExecutionException: ui.force.components.controllers.field.InputFieldProvider: org.auraframework.throwable.AuraRuntimeException: Error Retrieving Field for: v.batch.WAVY__DefaultChartofAccounts__c
  • If I add back the “WAVY__” namespace to the object in the Scratch Org, the code executes without error.
VS Code Version:
1.42.0
SFDX CLI Version:
47.18.0
OS and version:
Windows 10

Any input would be greatly appreciated.

Thank you.
Mike


 
Vivek.GuptaVivek.Gupta

HI Mike,

If you creating a scratch org with namespace then all objects, fields or components have that prefix in default. You can't access them without namespace as like manage package components.

mikechayesmikechayes
Hello Vivek.

This problem is when I pull the code from the packaging org with:
sfdx force:mdapi:retrieve -s -r ./mdapipkg -u mike@mail.com -p WAVYPackage
the prefix is removed from ALL 'sobjectType' in the lightning components.  Below is an example where the prefix has been removed during the 'sfdx force:mdapi:retrieve...'
<aura:attribute name="Batch" type="Batch__c" access="GLOBAL" default="{ sobjectType: 'Batch__c' }" />