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
-_--_- 

Confusing error in STG_Settings VF Page included with HEDA Unmanaged package in sandbox environment

Hi All,

A client of mine is having trouble viewing the STG_Settings vf page in their sandbox environment.  This page is part of the Salesfore developed HEDA unmanaged package.

The issue is question is on page load the following error is thrown:
An internal server error has occurred
Error ID: 944520837-278048 (319857279)

I have installed the managed package version of the same package in a developer org and am able to view the page just fine.

In the VF Page I have traced the issue to the section of the code below (towards bottom where it says "<-- THIS IS WHERE MY ISSUE LIES"
<apex:page showHeader="true" standardStylesheets="false" applyBodyTag="false" docType="html-5.0" controller="STG_Base_CTRL">
    <script src="/soap/ajax/35.0/connection.js" type="text/javascript"></script>
    <script src="/soap/ajax/35.0/apex.js" type="text/javascript"></script>
    <script src="/lightning/lightning.out.js" type="text/javascript"></script>
	
    <div class="slds">
        <!-- layout=block makes the outputPanel produce a DIV -->
        <apex:outputPanel layout="block" id="stgContainer" rendered="{!hasPerm}"></apex:outputPanel>
        
        <!-- No Access without Profile.PermissionsCustomizeApplication -->
        <apex:outputPanel layout="block" rendered="{!NOT(hasPerm)}">
            <h1 style="font-size: 1.5em;">You do not have permission to view this page.</h1> 
            <p>Please contact your administrator if you require access.</p>
        </apex:outputPanel>
    </div>

    <script>
        //Because sometimes the session ID is not set correctly
        sforce.connection.sessionId = "{!$Api.Session_ID}";		
		
        // We dont know the ID (because visualforce) so were gonna use a CSS selector to get it
        var stgContainerId = document.querySelector('[id$="stgContainer"]').id;
        
        var namespace = '';
        var namespacePrefix = '';
        
		//This would work with any class. We are just using the one with the shortest name.
        var gettingnamespace = sforce.connection.query("SELECT NamespacePrefix FROM ApexClass where Name = 'REL_Utils' LIMIT 1"); 
        var getname = gettingnamespace.getArray("records");
		if(getname.length > 0) { 
		    namespace = getname[0].NamespacePrefix;
		    if(namespace && namespace.length > 0) {
		      namespacePrefix = namespace + '__';
		    }
		}
        if(!namespace || namespace.length === 0) {
            namespace = "c";
        }
        
        $Lightning.use(namespace + ":STG_App", function() {  <-- THIS IS WHERE MY ISSUE LIES
            loadComponents(namespacePrefix);
        });
        
        function loadComponents(namespacePrefix) {
            $Lightning.createComponent(namespace + ":STG_CMP_Container", {namespacePrefix : namespacePrefix} ,stgContainerId);
        }
    </script>
</apex:page>

Now it's worth mentioning that since this is an unmanaged package there is no namespaceprefix to the VF page so the default is being leveraged "c".  That being said this code I believe should rightfully fail since the namespaceprefix (based on their code) is never being set. 
Now I have tried to rectify this by setting the namespaceprefix to "c" as well but end up getting the same error.

I'm not sure how to proceed debugging at this point as the exact same code works in my dev org albeit, as a managed package with the namespacreprefix intact.

Any help is greatly appreciated.

Thanks!
 
-_--_-
Sorry it's actually the loadComponents method that is failing at line 44 in the code snippet in my original post.

Thanks