Skip to content

Instantly share code, notes, and snippets.

@mjgallag
Created June 8, 2012 16:15
Show Gist options
  • Select an option

  • Save mjgallag/2896541 to your computer and use it in GitHub Desktop.

Select an option

Save mjgallag/2896541 to your computer and use it in GitHub Desktop.
BUG FIXED! Type.forName Specific SObject List Summer '12 (25.0) Week of June 4th Patch Regression Bug
// Per Rich Unger should be fixed in Week of June 11th Patch - https://twitter.com/rich_unger/status/210844950722641920
System.assert(Type.forName('List<' + Account.SObjectType.getDescribe().getName() + '>').newInstance() instanceOf Account[]);
// Workaround (slightly less efficient)
static Map<String, SObject[]> listInstancesBySObjectNames = new Map<String, SObject[]>{};
static SObject[] newListInstance(SObjectType sObjectType) {
if (!listInstancesBySObjectNames.containsKey(sObjectType.getDescribe().getName()))
listInstancesBySObjectNames.put(sObjectType.getDescribe().getName(),
Database.query('SELECT Id FROM ' + sObjectType.getDescribe().getName() + ' WHERE Id = null'));
return listInstancesBySObjectNames.get(SObjectType.getDescribe().getName()).clone();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment