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
sanjaypatidarsanjaypatidar 

Schema Describe in System Mode.

Hi All,

 

I have written a class where i am passing an Object and getting the details of all the fields in the object. This class runs fine when the user have access to the object/fields, but if the user do not have access to the object/fields returns null.

 

Code Below  -

        // Get a map of field name and field token
        Map<String, Schema.SObjectField> fMap = Schema.getGlobalDescribe().get(objectName.toLowerCase()).getDescribe().Fields.getMap();
        list<string> selectFields = new list<string>();
         system.debug('***- '+fMap);
        if (fMap != null)
            {
            for (Schema.SObjectField ft : fMap.values())
                { // loop through all field tokens (ft)
                system.debug('LLL');
                Schema.DescribeFieldResult fd = ft.getDescribe(); // describe each field (fd)
                if (fd.isCreateable())
                    { // field is creatable
                      // I need to add all the fields in the object which can be created irrespective of whether the logged in user has read access or write access on it or even for that matter if he even do not have access on the Object. 
                    selectFields.add(fd.getName());
                    }
                }
            }

 // I need to add all the fields in the object which can be created irrespective of whether the logged in user has read access or write access on it or even for that matter if he even do not have access on the Object. 

 

Thanks in Advance,

Sanjay

Andy BoettcherAndy Boettcher

If the logged in user doesn't have access to the sObject / fields, the user doesn't have access.  You cannot change the security / user context you are running APEX within.

 

You may have some options with Batch and Scheduled APEX, but you'd have to tinker to be sure.