-
clearMapsInTest ()
If we are running a test, clear sObject maps. We do this to avoid using @TestVisible on the maps themselves
This is
private and TestVisible so it cannot be called in production code context
-
fillMapsForObject (objectName)
Gets record type maps for a new sObject
We check in each public method if the sObject has already been described so we do
not eagerly load DescribeSObjectResult
-
getAllRecordTypesForSelectList (objectName)
Make a Visualforce picklist with ALL RecordType Names displayed and the
RecordType Id as the value
Unavailable Record Types will be _disabled_ in the picklist.
-
getAllRecordTypesForSelectList (objectName, disableUnavailable)
Make a Visualforce picklist with ALL RecordType Names displayed and the
RecordType Id as the value
Unavailable Record Types can be disabled in the picklist by
setting disableUnavailable to true..
-
getAvailableRecordTypeDevNameIdMap (objectName)
Gives a map of all available (to the running user) RecordTypeIds by
developername for an sObject
-
getAvailableRecordTypeNameIdMap (objectName)
Gives a map of all available (to the running user) RecordTypeIds by name for an sObject
-
getAvailableRecordTypesForSelectList (objectName)
Make a Visualforce picklist of only available Record Types with the RecordType Name displayed
and the RecordType Id as the value. No options are disabled.
-
getAvailableRecordTypesIdSet (objectName)
Gives a set of all available (to the running user) RecordTypeIds for an sObject
-
getDefaultRecordType (objectName)
Given an sObject Name, return the default Record Type Id for the running user
-
getDefaultRecordTypeDevName (objectName)
Given an sObject Name, return the default Record Type DeveloperName for the running user
-
getDefaultRecordTypeId (objectName)
Given an sObject Name, return the default Record Type Id for the running user
-
getDefaultRecordTypeName (objectName)
Given an sObject Name, return the default Record Type Name for the running user
-
getRecordTypeDevNameFromId (objectName, recordTypeId)
Given an sObject and RecordType Id, return the
RecordType DeveloperName
This saves a query on the
RecordType object
-
getRecordTypeDevNameFromId (recordTypeId)
Generate map of all record type developerNames by Id & return Record Type DeveloperName
This is an overloaded method
for efficiency, using only the Id
-
getRecordTypeDevNameFromName (objectName, recordTypeName)
Given an sObject and RecordType Name, return the RecordType Id
Note: Since RecordType.Name is not unique, this section could give unpredicable results
If possible, DO NOT USE this method - use a method with RecordType.DeveloperName instead
-
getRecordTypeDevNameIdMap (objectName)
Gives a map of all record type IDs by DeveloperName for an sObject
Returns Master record type if no other RTs available
-
getRecordTypeFromDevName (objectName, recordTypeDevName)
Given an sObject and RecordType DeveloperName, return the
RecordType Id
-
getRecordTypeFromId (recordTypeId)
Given a RecordType Id, return the Record Type object
-
getRecordTypeFromId (objectName, recordTypeId)
Given an sObject and RecordType Id, return the
Record Type object
-
getRecordTypeFromName (objectName, recordTypeName)
Given an sObject and RecordType Name, return the
RecordType object
Note: Since RecordType.Name is not
unique, this section could give unpredicable results
If possible, DO NOT USE this method - use a method with
RecordType.DeveloperName instead
-
getRecordTypeIdFromDevName (objectName, recordTypeDevName)
Given an sObject and RecordType DeveloperName, return the
RecordType Id
This should be the most-used method in this class
-
getRecordTypeIdFromName (objectName, recordTypeName)
Given an sObject and RecordType Name, return the RecordType Id
Note: Since RecordType.Name is not unique, this section could give unpredicable results
If possible, DO NOT USE this method - use a method with RecordType.DeveloperName instead
-
getRecordTypeIdSetFromDevNames (objectName, recordTypeDevNameSet)
Gives a set of RecordType Ids from an sObject and a set of
RecordType DeveloperNames
-
getRecordTypeNameFromDevName (objectName, recordTypeDevName)
Given an sObject and RecordType DeveloperName, return the
RecordType Name
-
getRecordTypeNameFromId (objectName, recordTypeId)
Given an sObject and RecordType Id, return the RecordType Name
-
getRecordTypeNameFromId (recordTypeId)
Generate map of all record type names by Id & return Record Type Name
-
getRecordTypeNameIdMap (objectName)
Gives a map of all RecordType IDs by name for an sObject
-
getRecordTypesForObject (objectName)
Gives a list of all the RecordTypeInfo object records for an sObject
This list has more
items than just the record types available to the running user.
This method has no immediately obvious uses, but perhaps
an outside library will need this list for, say, a project for a LWC.
-
getStringRecordTypesForSelectList (objectName)
Make a Visualforce picklist with the RecordType Name displayed and the
RecordType Name as the value
-
isRecordTypeAvailable (objectName, recordTypeDevName)
Is this record type (identified by developer name) available (and active) for the current user?
-
isRecordTypeDefault (objectName, recordTypeDevName)
Is this record type (identified by developer name) the default record type for the current user?
If we are running a test, clear sObject maps. We do this to avoid using @TestVisible on the maps themselves
This is private
and TestVisible so it cannot be called in production code context
Signature
@TestVisible
private static void clearMapsInTest()
Gets record type maps for a new sObject
We check in each public method if the sObject has already been described so we do
not eagerly load DescribeSObjectResult
Signature
private static void fillMapsForObject(String objectName)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
Author
Make a Visualforce picklist with ALL RecordType Names displayed and the
RecordType Id as the value
Unavailable Record Types will be _disabled_ in the picklist.
Signature
global static List<SelectOption> getAllRecordTypesForSelectList(String objectName)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
Returns
List<SelectOption> Visualforce SelectOption list
Author
Make a Visualforce picklist with ALL RecordType Names displayed and the
RecordType Id as the value
Unavailable Record Types can be disabled in the picklist by
setting disableUnavailable to true..
Signature
@SuppressWarnings('PMD.AvoidBooleanMethodParameters')
global static List<SelectOption> getAllRecordTypesForSelectList(String objectName, Boolean disableUnavailable)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
disableUnavailable
Type: Boolean
Should we disable unavailable RTs in the SelectList?
Returns
List<SelectOption> Visualforce SelectOption list
Author
Gives a map of all available (to the running user) RecordTypeIds by
developername for an sObject
Signature
global static Map<String, Id> getAvailableRecordTypeDevNameIdMap(String objectName)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
Returns
Map<String, Id> Map<RecordType Name, RecordType Id>
Authors
Since
2023 Use available record types map
Gives a map of all available (to the running user) RecordTypeIds by name for an sObject
Signature
global static Map<String, Id> getAvailableRecordTypeNameIdMap(String objectName)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
Returns
Map<String, Id> Map<RecordType Name, RecordType Id>
Authors
Since
2023 Use available record types map
Make a Visualforce picklist of only available Record Types with the RecordType Name displayed and
the RecordType Id as the value. No options are disabled.
Signature
global static List<SelectOption> getAvailableRecordTypesForSelectList(String objectName)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
Returns
List<SelectOption> Visualforce SelectOption list
Author
Evan Callahan
Example
RecordTypes.getAvailableRecordTypesForSelectList('Account')
System.SelectOption[value="<SFID>", label="Available", disabled="false"]
System.SelectOption[value="<SFID>", label="Default", disabled="false"]
System.SelectOption[value="<SFID>", label="Inactive", disabled="true"]
Gives a set of all available (to the running user) RecordTypeIds for an sObject
Signature
global static Set<Id> getAvailableRecordTypesIdSet(String objectName)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
Returns
Set<Id> Map<RecordType Name, RecordType Id>
Authors
Since
2024 Use available record types map to generate set
Given an sObject Name, return the default Record Type Id for the running user
Signature
@SuppressWarnings('PMD.AvoidDeeplyNestedIfStmts')
global static Schema.RecordTypeInfo getDefaultRecordType(String objectName)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
Returns
Id Default Record Type Id for the running user for this object
Given an sObject Name, return the default Record Type DeveloperName for the running user
Signature
global static String getDefaultRecordTypeDevName(String objectName)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
Returns
String Default Record Type DeveloperName for the running user for this object
Given an sObject Name, return the default Record Type Id for the running user
Signature
global static Id getDefaultRecordTypeId(String objectName)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
Returns
Id Default Record Type Id for the running user for this object
Given an sObject Name, return the default Record Type Name for the running user
Signature
global static String getDefaultRecordTypeName(String objectName)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
Returns
String Default Record Type Name for the running user for this object
Given an sObject and RecordType Id, return the
RecordType DeveloperName
This saves a query on the
RecordType object
Signature
global static String getRecordTypeDevNameFromId(String objectName, Id recordTypeId)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
recordTypeId
Type: Id
RecordType Id
Returns
RecordType DeveloperName
See
getRecordTypeDevNameFromId
Author
Generate map of all record type developerNames by Id & return Record Type DeveloperName
This is an overloaded method for
efficiency, using only the Id
Signature
global static String getRecordTypeDevNameFromId(Id recordTypeId)
Parameters
recordTypeId
Type: Id
RecordTypeId
Returns
String Record Type Name
See
getRecordTypeDevNameFromId
Author
Since
2022-03-29
Given an sObject and RecordType Name, return the RecordType Id
Note: Since RecordType.Name is not unique, this section could give unpredicable results
If possible, DO NOT USE this method - use a method with RecordType.DeveloperName instead
Signature
global static String getRecordTypeDevNameFromName(String objectName, String recordTypeName)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
recordTypeName
Type: String
RecordType Name (can include spaces)
Returns
RecordType.DeveloperName
Author
Example
RecordTypes.getRecordTypeDevNameFromName('Account','Person Account')
Gives a map of all record type IDs by DeveloperName for an sObject
Returns Master record type if no other RTs available
Signature
global static Map<String, Id> getRecordTypeDevNameIdMap(String objectName)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
Returns
Map<String, Id> Map<recordTypeDevName, RecordType Id>
Author
Given an sObject and RecordType DeveloperName, return the
RecordType Id
Signature
global static Schema.RecordTypeInfo getRecordTypeFromDevName(String objectName, String recordTypeDevName)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
recordTypeDevName
Type: String
RecordType.DeveloperName (cannot include spaces)
Returns
Schema.RecordTypeInfo RecordTypeInfo object
Author
Example
RecordTypes.getRecordTypeFromDevName('Account','Person_Account')
Given a RecordType Id, return the Record Type object
Signature
global static Schema.RecordTypeInfo getRecordTypeFromId(Id recordTypeId)
Parameters
recordTypeId
Type: Id
RecordType Id
Returns
Schema.RecordTypeInfo RecordTypeInfo object
Author
Given an sObject and RecordType Id, return the
Record Type object
Signature
global static Schema.RecordTypeInfo getRecordTypeFromId(String objectName, Id recordTypeId)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
recordTypeId
Type: Id
RecordType Id
Returns
Schema.RecordTypeInfo RecordTypeInfo object
Author
Given an sObject and RecordType Name, return the
RecordType object
Note: Since RecordType.Name is not
unique, this section could give unpredicable results
If possible, DO NOT USE this method - use a method with
RecordType.DeveloperName instead
Signature
global static Schema.RecordTypeInfo getRecordTypeFromName(String objectName, String recordTypeName)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
recordTypeName
Type: String
RecordType Name (can include spaces)
Returns
Schema.RecordTypeInfo RecordTypeInfo object
Author
Example
RecordTypes.getRecordTypeFromName('Account','Person Account')
Given an sObject and RecordType DeveloperName, return the
RecordType Id
This should be the most-used method in this class
Signature
global static Id getRecordTypeIdFromDevName(String objectName, String recordTypeDevName)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
recordTypeDevName
Type: String
RecordType.DeveloperName (cannot include spaces)
Returns
RecordType Id
Author
Example
RecordTypes.getRecordTypeIdFromDevName('Account','Person_Account')
Given an sObject and RecordType Name, return the RecordType Id
Note: Since RecordType.Name is not unique, this section could give unpredicable results
If possible, DO NOT USE this method - use a method with RecordType.DeveloperName instead
Signature
global static Id getRecordTypeIdFromName(String objectName, String recordTypeName)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
recordTypeName
Type: String
RecordType Name (can include spaces)
Returns
RecordType Id
Author
Example
RecordTypes.getRecordTypeIdFromName('Account','Person Account')
Gives a set of RecordType Ids from an sObject and a set of
RecordType DeveloperNames
Signature
global static Set<Id> getRecordTypeIdSetFromDevNames(String objectName, Set<String> recordTypeDevNameSet)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
recordTypeDevNameSet
Type: Set<String>
Set of DeveloperNames
Returns
Set<Id> All RecordType IDs for a given sObject
Author
Example
Set<String> rtNames = new Set<String> {'Person_Account', 'Customer'};
getRecordTypeIdSetFromDevNames('Account', rtNames);
Given an sObject and RecordType DeveloperName, return the
RecordType Name
Signature
global static String getRecordTypeNameFromDevName(String objectName, String recordTypeDevName)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
recordTypeDevName
Type: String
RecordType.DeveloperName (cannot include spaces)
Returns
RecordType Name
Author
Example
RecordTypes.getRecordTypeNameFromDevName('Account','Person_Account')
Given an sObject and RecordType Id, return the RecordType Name
Signature
global static String getRecordTypeNameFromId(String objectName, Id recordTypeId)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
recordTypeId
Type: Id
RecordType Id
Returns
RecordType Name
Author
Generate map of all record type names by Id & return Record Type Name
Signature
global static String getRecordTypeNameFromId(Id recordTypeId)
Parameters
recordTypeId
Type: Id
RecordTypeId
Returns
String Record Type Name
Author
Since
2022-03-29
Gives a map of all RecordType IDs by name for an sObject
Signature
global static Map<String, Id> getRecordTypeNameIdMap(String objectName)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
Returns
Map<String, Id> Map<RecordType Name, RecordType Id>
Author
Evan Callahan
Gives a list of all the RecordTypeInfo object records for an sObject
This list has more
items than just the record types available to the running user.
This method has no immediately obvious uses, but perhaps an
outside library will need this list for, say, a project for a LWC.
Signature
global static List<Schema.RecordTypeInfo> getRecordTypesForObject(String objectName)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
Returns
List<Schema.RecordTypeInfo> List of all record types for the object (active and inactive)
Author
Make a Visualforce picklist with the RecordType Name displayed and the
RecordType Name as the value
Signature
global static List<SelectOption> getStringRecordTypesForSelectList(String objectName)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
Returns
List<SelectOption> Visualforce SelectOption list
Author
Evan Callahan
Is this record type (identified by developer name) available (and active) for the current user?
Signature
public static Boolean isRecordTypeAvailable(String objectName, String recordTypeDevName)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
recordTypeDevName
Type: String
RecordType.DeveloperName (cannot include spaces)
Returns
Boolean Is this Record Type available to the running user?
Is this record type (identified by developer name) the default record type for the current user?
Signature
public static Boolean isRecordTypeDefault(String objectName, String recordTypeDevName)
Parameters
objectName
Type: String
SObject name (with __c if custom, etc)
recordTypeDevName
Type: String
RecordType.DeveloperName (cannot include spaces)
Returns
Boolean Is this Record Type the default for the running user?