I'm looking for some clarification on the behavior of dynamic apex.

I am seeing some inconsistent behavior around schema global describe and sobject describe field maps.

In the below example Rule__c is a custom table that is unmanaged.

// below executed in transaction started in AuraEnabled method and will return null for user with standard profile, but works for sys admin

// below executed in transaction started in AuraEnabled method 
// will return null for user with standard profile, but works for sys admin

Does this seem strange to anybody? Has anybody encountered this before? I'm thinking about building a wrapper for describe information to fill in the gaps as they are found, since the code is able to directly access Rule__c.SObjectType and AssignRule__c.Course_Session__c.




2 Answers 2


There should be no impact of user permissions or sharing settings on the behavior of dynamic apex (except when executing anonymously Understanding Describe Information Permissions).

There seems to be a platform issue that is caused by some combination of a user's permissions and the properties of certain custom objects that causes keys for fields and sobjects to be missing from both the Schema.getGlobalDescribe() map and SObjectDescribe.fields.getMap() map.

A workaround is to call getGlobalDescribe() from a without sharing context. This seems to cause calls to Schema.getGlobalDescribe() from sharing context to work as expected, and also calls to SObjectDescribe.fields.getMap() from a sharing context to work as expected.

public without sharing class GlobalDescribeWorkaround { 
    public static Map<String,Schema.SObjectType> getGlobalDescribe() {
        return Schema.getGlobalDescribe();

This bug may have been fixed in Winter 2020 release https://releasenotes.docs.salesforce.com/en-us/winter20/release-notes/rn_apex_enable_improved_schema_caching.htm

  • Welcome to Salesforce SE! While this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – identigral
    Dec 18, 2019 at 1:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .