While I was working on a Visualforce page which has some similar functionality to another page that has already been developed in the past into one of my other orgs, I decided to re-use the same code to save some time.
After I did all the refactoring and went to test the page I got:
Attempt to de-reference a null object
in my piece of code that was performing a Describe
method for a field, which has previously been retrieved by the Schema.GetGlobalDescribe()
method.
I found that odd because the very same functionality works without a problem into the old org. Then I thought it might be Field Level Security for that particular field. Went to check that, the FLS was set to false for all profiles, which made me go in the old org and try the same. After I disabled FLS in the old org, the page was still working without the problem, I was able to get the field name and perform a Describe
on it.
Last thing that would be different was the API version of the Class. The old org was running v26.0 and the new one v34.0. That made me run some experiments which resulted in the following:
TL;DR;
- The access to the sObject fields in
Schema.GetGlobalDescribe()
has been changed in v34.0.
Below is the code and the result respectively, running in v33.0 and below and v34.0 and above:
Schema.GetGlobalDescribe().Get(SObjectName).GetDescribe().Fields.GetMap().get('Field__c').getDescribe().getName()
v33.0 and below
output: Field__c
v34.0 and above
output: System.NullPointerException: Attempt to de-reference a null object
So I went to check the release notes for Summer '15 (v34.0) and I could not find any reference to the changes made to these Classes/Methods.
I'm wondering whether this is a bug, or expected behaviour and was missed in the documentation. Potentially this could break existing code if the API version of the Apex is changed.