Find your content:

Search form

You are here

Schema.getGlobalDescribe returning different data from Developer Console

 
Share

I'm trying to see if an object exists using the following code:

public with sharing class GenericUtils {
     public static Boolean doesObjectExist(String objectName) {
          Map<String, Schema.SObjectType> result = Schema.getGlobalDescribe();
          return result.containsKey(objectName);
     }
}

When I run the following in the Developer console, it returns false.

System.debug(GenericUtils.doesObjectExist('LiveChatTranscript'));

However, when I run this in the Developer console, it returns true.

Map<String, Schema.SObjectType> result = Schema.getGlobalDescribe();
System.debug(result.containsKey('LiveChatTranscript'));

I have tried making the GenericUtils class both with and without sharing with no change in outcome. When I inspect the keySet of the map they return two different sets of data. Is there something that I am missing, or is this expected behavior?


Attribution to: Patrick Connelly

Possible Suggestion/Solution #1

This post suggests that you need to add access to the GenericUtils Apex class to the profile of your running user. https://stackoverflow.com/questions/9627809/do-calls-to-schema-getglobaldescribe-not-run-in-system-context-in-classes-decl

I'd give that a whirl. Also, I suspect that perhaps with / without sharing may behave differently, so try without sharing and see if that might also fix your issue.


Attribution to: James Loghry

Possible Suggestion/Solution #2

What is the API version of the GenericUtils class? If it's API v24.0 or lower then the LiveChatTranscript sObject type isn't valid and won't be returned by calls to Schema.getGlobalDescribe().

The webservice API docs contain the minimum API version for each sObject type: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_livechattranscript.htm


Attribution to: ca_peterson
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/5414

My Block Status

My Block Content