New Schema.describeSObjects not working as expected

There is a new method for Schema in Winter 14 called Schema.describeSObjects. The idea as I understand the docs is that you can pass in a list of sObject names as strings, and get back the describe results for each of them in a list of results. But it doesn’t seem to working as I would expect, but maybe I am just missing something obvious…

As I understand it, these calls should return the same information. The new method returns the basic info, but when I request the recordtypeinfo, I get back null…

Schema.DescribeSObjectResult r = Account.sObjectType.getDescribe();
system.debug(r); //Returns basic describe info 
system.debug(r.getRecordTypeInfosByName()); //Returns all the record types

String[] types = new String[]{'Account'};
List<Schema.DescribeSobjectResult> results = Schema.describeSObjects(types);
system.debug(results); //Returns the same basic describe info
system.debug(results[0].getRecordTypeInfosByName()); //**returns null**

Answer

So support confirmed that this was happening, but I don’t see it in Known Issues, so I guess it it a limitation for now – I’ll raise an idea and see what happens. For now though, you can follow Daniel’s suggestion and build your own map:

String[] types = new String[]{'Account'};
List<Schema.DescribeSobjectResult> results = Schema.describeSObjects(types);
Map<String, Schema.RecordTypeInfo> rmap = new Map<String, Schema.RecordTypeInfo> ();

for (Schema.RecordTypeInfo ri: results[0].getRecordTypeInfos()) {
        rmap.put(ri.getname(), ri);//use ri.getRecordTypeId() for an Id map 
    }

Attribution
Source : Link , Question Author : BritishBoyinDC , Answer Author : Community

Leave a Comment