6

I read in Accessing All Field Describe Results for an sObject:

Use the field describe result's getMap method to return a map that represents the relationship between all the field names (keys) and the field tokens (values) for an sObject.

Map<String, Schema.SObjectField> fieldMap = Schema.SObjectType.Account.fields.getMap();

The map has the following characteristics:

All field names are case insensitive.

While the documentation for Maps says:

Map keys of type String are case-sensitive.

QUESTION

Is the field describe result map a special type of Map? It's quite frustrating to have one type of Map in apex to behave differently.

6

In the object oriented "is a" sense, at least at compile time, they both support these Map methods. But the implementing class might be this for the describe map:

Map<String, String> m = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);

and this for most other maps:

Map<String, String> m = new HashMap<String, String>();

Other languages would make the distinction between interface and implementation a bit clearer by providing the contract (the methods) in an interface.

I agree being case insensitive in some places but not in others can be confusing.

  • 3
    +1 It'd be incredibly nice if they gave us the option to write case-insensitive maps without writing an entire wrapper class dedicated to that purpose. – sfdcfox Dec 15 '18 at 12:51
  • @sfdcfox Agreed. Or Generic types so you don't have to keep re-implementing for various types. – Keith C Dec 15 '18 at 12:53

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.