+ Start a Discussion
RoyGiladRoyGilad 

Schema.getGlobalDescribe in managed package

Managed package question!
I have a simple code that works outside the managed package (MP), but when I put it inside the MP it just gives me the objects within the package, and not all of the org's objects:
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
                    Map<string, string> sObjectNameToLabel = new Map<string, string> ();
                    
                    for(Schema.SObjectType d : schemaMap.values())
                    {
                        Schema.DescribeSObjectResult ds = d.getDescribe();
                        sObjectNameToLabel.put(ds.getName(),ds.getLabel());
                    }
Any ideas?
Nir Keren 14Nir Keren 14
Hi Roy,
Did u managed to solve it?
GennadiyGennadiy
Hi Roy.

May I ask you whether you found a solution or at least explanation to this issue?

We are having exatcly the same problem in our DEV org, where we develop a managed package. This org is pretty old (about 6-7 years).

Also we have a new DEV org created a couple of months ago and we also created another managed package there. What is interesting is that I don't see the issue in this org. The Schema.getGlobalDescribe() method returns all objects.

This makes me think that the issue may be related to system bugs in old SF instances.
RoyGiladRoyGilad
Hi I dont remember the solution at the moment ( will try to search my memory), but by the behaviour you are describing I would suggest to upgrade the class API version and to try again. I will see if I can replicate the issue.
GennadiyGennadiy
Roy, I'm using the newest version (API 46.0) in both orgs.
GennadiyGennadiy
Roy, this really looks like a Salesforce defect. Several years ago there was a setting in a managed package that was controlling API Access level: "Restrcited" or "Unrestrcited". If it was set to Restricted, then a package's code could see only objects within the package and some additional allowed objects. Some years ago this setting has been deprecated and removed from Salesforce UI, but it's still used by SF internally. It's not possible to change API Access for new packages and they are always unrestricted, but the defect is in the fact that we can't delete restrcition for old packages via Salesforce UI.

We were able to resolve the problem along with Salesforce support. What they did for us was that they temporarily enabled this deprecated setting, it appeared in SF UI again, we changed it to "Unrestricted" and then they disabled it again. So, we were lucky, since we have an account with  Parner Support.