Skip to content

Instantly share code, notes, and snippets.

@jbro-io
Last active December 24, 2015 15:19
Show Gist options
  • Select an option

  • Save jbro-io/6819620 to your computer and use it in GitHub Desktop.

Select an option

Save jbro-io/6819620 to your computer and use it in GitHub Desktop.
public class ObjectUtil
{
public static String getObjectRecordTypeId(SObjectType sObjectType, String recordTypeName)
{
//Generate a map of tokens for all the Record Types for the desired object
Map<String, RecordTypeInfo> recordTypeInfo = sObjectType.getDescribe().getRecordTypeInfosByName();
system.debug('RECORD TYPES:' + recordTypeInfo);
if(!recordTypeInfo.containsKey(recordTypeName))
throw new RecordTypeException('Record type "'+ recordTypeName +'" does not exist.');
//Retrieve the record type id by name
return recordTypeInfo.get(recordTypeName).getRecordTypeId();
}
public class RecordTypeException extends Exception{}
}
@jbro-io
Copy link
Copy Markdown
Author

jbro-io commented Oct 4, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment