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
Sumit Kumar Singh 9Sumit Kumar Singh 9 

Schema.getGlobalDescribe() not working in API version 36

Hello Experts, 

I am experiencing an unexpected situation. Below code works fine in API version 26 but in API Version 36, Its throwing an exception "Attempt ro re-deference a null object."
I debug it and came to know that  "objToken" is coming null. Why???
String objectName = 'Account';
SObjectType objToken = Schema.getGlobalDescribe().get(objectName);
DescribeSObjectResult objDef = objToken.getDescribe();
Map<String, SObjectField> field = objDef.fields.getMap();

Amit Chaudhary 8Amit Chaudhary 8
Please try below code.
String SobjectApiName = 'Account';
 Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
 Map<String, Schema.SObjectField> fieldMap = schemaMap.get(SobjectApiName).getDescribe().fields.getMap();
Let us know if that will work

Sumit Kumar Singh 9Sumit Kumar Singh 9
Hello Amit,
Thanks for your response.
It didn't work in Dev acount with API version 36.
I could re-write in one line; but the problem is that it's also not working in API version 36. 
Map<String, SObjectField> field = Schema.getGlobalDescribe().get(parsedRequest.objectName).getDescribe().fields.getMap();
Sumit Kumar Singh