Last active
December 24, 2015 15:19
-
-
Save jbro-io/6819620 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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{} | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
getObjectRecordTypeId: http://www.jonathanbroquist.com/blog/2013/10/retrieving-sobject-recordtypeid-dynamically-with-salesforce/