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**
  • 1
    Not sure what is going on there. Oddly, .getRecordTypeInfos() seems to work fine. You could use that to rebuild the Map if required. – Daniel Ballinger Oct 16 '13 at 1:21
  • That is unexpected, both getRecordTypeInfosById() and getRecordTypeInfosByName() doesn't work but getRecordTypeInfos does. There is nothing seems to be missed in sample code. – Ashwani Oct 16 '13 at 6:22
  • Yep, most odd, i performed the same checks as @reddev and scanned the docs for any hint of a limitation comment and found nothing, thus concluding.... you've found a platform bug. I'd also agree with Daniel about the workaround in the meantime. – Andrew Fawcett Oct 16 '13 at 8:17
  • Ok - thanks to everyone for the sanity check - let me see what Developer Support has to say on this issue.. – BritishBoyinDC Oct 16 '13 at 16:04
  • Heard back from dev support...they ran our code and confirmed we are right...and offered Daniel's solution as the workaround...I'll update again in support hears more from R&D – BritishBoyinDC Oct 24 '13 at 20:47

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 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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