- This class is allows for easy, readable access to Record Type information from other classes.
Written by Evan Callahan, copyright (c) 2010 Groundwire
Updated by David Schach, copyright (c) 2021 X-Squared on Demand
This program is released under the GNU General Public License. http://www.gnu.org/licenses/
This class is meant to allow for access to Record Type information from within other classes.
It is called statically, and therefore will supply the same information to all calls made from within one transaction, or set of trigger calls. This is beneficial because this info should be the same for all calls in a transaction, and by calling it statically we reduce the calls that are made, making the total transaction more efficient.
Usage recommendation: Always use DeveloperName instead of Name, as this is more likely to be hard-coded in places, while the Name is actually a label and may change (especially due to user language).
+ This class is allows for easy, readable access to Record Type information from other classes.
Written by Evan Callahan, copyright (c) 2010 Groundwire
Updated by David Schach, copyright (c) 2021 X-Squared on Demand
This program is released under the GNU General Public License. http://www.gnu.org/licenses/
This class is meant to allow for access to Record Type information from within other classes.
It is called statically, and therefore will supply the same information to all calls made from within one transaction, or set of trigger calls. This is beneficial because this info should be the same for all calls in a transaction, and by calling it statically we reduce the calls that are made, making the total transaction more efficient.
Usage recommendation: Always use DeveloperName instead of Name, as this is more likely to be hard-coded in places, while the Name is actually a label and may change (especially due to user language).
An easy-to-read table with the various methods, their inputs, and their outputs is available at RecordTypesHome
Signature
@@ -152,7 +152,7 @@
RecordTypes Properties
-
+
allRecordTypes
|
@@ -168,7 +168,7 @@ RecordTypes Properties
|
-
+
availableRecordTypesMap
|
@@ -184,7 +184,7 @@ RecordTypes Properties
|
-
+
defaultRecordTypeIds
|
@@ -200,7 +200,7 @@ RecordTypes Properties
|
-
+
defaultRecordTypes
|
@@ -216,7 +216,7 @@ RecordTypes Properties
|
-
+
gd
|
@@ -232,7 +232,7 @@ RecordTypes Properties
|
-
+
recordTypesByDevName
|
@@ -248,7 +248,7 @@ RecordTypes Properties
|
-
+
recordTypesById
|
@@ -264,7 +264,7 @@ RecordTypes Properties
|
-
+
recordTypesByName
|
@@ -280,7 +280,7 @@ RecordTypes Properties
|
-
+
recordTypesIdMap
|
@@ -324,7 +324,7 @@ RecordTypes Methods
- Make a Visualforce picklist with the RecordType Name displayed and the RecordType Id as the value
+ 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
@@ -381,15 +381,6 @@ RecordTypes Methods
Given an sObject Name, return the default Record Type Name for the running user
-
-
- getRecordType (objectName, recordTypeId)
-
-
-
- Given an sObject and RecordType Id, return the RecordType object
-
-
getRecordTypeDevNameFromId (objectName, recordTypeId)
@@ -531,7 +522,7 @@ RecordTypes Methods
- Make a Visualforce picklist with the RecordType Name displayed and the RecordType Id as the value
+ Make a Visualforce picklist of all available Record Types with the RecordType Name displayed and the RecordType Id as the value
@@ -547,7 +538,7 @@ RecordTypes Methods
|
+ RecordTypes
Record Types Utilities
-
+
Written by Evan Callahan, copyright (c) 2010 Groundwire
@@ -86,20 +87,18 @@ Record Types Utilities
This class is meant to allow for access to Record Type information from within other classes.
-
- It is called statically, and therefore will supply the same information to all calls made from within one transaction, or set of trigger calls. This is
- beneficial because this info should be the same for all calls in a transaction, and by calling it statically we reduce the calls that are made, making the
- total transaction more efficient.
+ It is called statically, and therefore will supply the same information to all calls made from within one transaction, or set of trigger calls. This is beneficial because this
+ info should be the same for all calls in a transaction, and by calling it statically we reduce the calls that are made, making the total transaction more efficient.
Updated by David Schach, copyright (c) 2021 X-Squared on Demand
- This class is allows for easy, readable access to Record Type information from other classes.
+ This class allows for easy, readable access to Record Type information from other classes.
- Usage recommendation: Always use DeveloperName instead of Name, as this is more likely to be hard-coded in places, while the Name is actually a label and may
- change (especially due to user language).
+ Usage recommendation: Always use DeveloperName instead of Name, as this is more likely to be hard-coded in places, while the Name is actually a label and may change (especially
+ due to user language).
|
diff --git a/docs/RecordTypesTest.html b/docs/RecordTypesTest.html
index 7f3ff18..cc23d15 100644
--- a/docs/RecordTypesTest.html
+++ b/docs/RecordTypesTest.html
@@ -39,7 +39,7 @@
@@ -191,7 +191,7 @@ RecordTypesTest Methods
-
+
resetTest()
@@ -215,7 +215,7 @@
-
+
testAccountRecordTypeReturns()
@@ -239,7 +239,7 @@
-
+
testAccountRecTypes()
@@ -287,7 +287,7 @@
-
+
testContactRecordType()
@@ -311,7 +311,7 @@
-
+
testSolutionRecTypes()
diff --git a/docs/assets/RecordTypesHome.html b/docs/assets/RecordTypesHome.html
index b4a75b7..11e1190 100644
--- a/docs/assets/RecordTypesHome.html
+++ b/docs/assets/RecordTypesHome.html
@@ -1,23 +1,198 @@
Record Types Utilities
-
Original Header
+
- Written by Evan Callahan, copyright (c) 2010 Groundwire
-
- This program is released under the GNU General Public License. http://www.gnu.org/licenses/
-
- This class is meant to allow for access to Record Type information from within other classes.
-
- It is called statically, and therefore will supply the same information to all calls made from within one transaction, or set of trigger calls. This is beneficial because this
- info should be the same for all calls in a transaction, and by calling it statically we reduce the calls that are made, making the total transaction more efficient.
+ Written by Evan Callahan, copyright (c) 2010 Groundwire
+
+ This program is released under the GNU General Public License. http://www.gnu.org/licenses/
+
+ This class is meant to allow for access to Record Type information from within other classes.
+
+ It is called statically, and therefore will supply the same information to all calls made from within one transaction, or set of trigger calls. This is
+ beneficial because this info should be the same for all calls in a transaction, and by calling it statically we reduce the calls that are made, making the
+ total transaction more efficient.
-
-
Additional/Changed Header
+
- Updated by David Schach, copyright (c) 2021 X-Squared on Demand
-
- This class is allows for easy, readable access to Record Type information from other classes.
-
- Usage recommendation: Always use DeveloperName instead of Name, as this is more likely to be hard-coded in places, while the Name is actually a label and may change (especially
- due to user language).
-
\ No newline at end of file
+ Updated by David Schach, copyright (c) 2021 X-Squared on Demand
+
+ This class is allows for easy, readable access to Record Type information from other classes.
+
+ Usage recommendation: Always use DeveloperName instead of Name, as this is more likely to be hard-coded in places, while the Name is actually a label and may
+ change (especially due to user language).
+
+
+
+
+
Less Common Methods
+
diff --git a/docs/assets/search-idx.js b/docs/assets/search-idx.js
index 94a7f9d..1365333 100644
--- a/docs/assets/search-idx.js
+++ b/docs/assets/search-idx.js
@@ -2,7 +2,7 @@ export default [
{
"title": "Home",
"fileName": "index.html",
- "text": "Home Record Types Utilities Written by Evan Callahan, copyright(c) 2010 Groundwire This program is released under the GNU General Public License. http://www.gnu.org/licenses/ This class is meant to allow for access to Record Type information from within other classes. It is called statically, and therefore will supply the same information to all calls made from within one transaction, or set of trigger calls. This is beneficial because this info should be the same for all calls in a transaction, and by calling it statically we reduce the calls that are made, making the total transaction more efficient. Updated by David Schach, copyright(c) 2021 X-Squared on Demand This class is allows for easy, readable access to Record Type information from other classes. Usage recommendation: Always use DeveloperName instead of Name, as this is more likely to be hard-coded in places, while the Name is actually a label and may change(especially due to user language). Record-Types This is a project based on work by Evan Callahan (formerly of Groundwire, and now at Salesforce) who wrote this class (Repo has been deleted. Sadface.) a long time ago to reduce the number of describe calls required to work with Record Types. I've updated the project(by pulling test code out of the main class - that's how old it was!) and have added some additional methods. The included test class has 100% coverage, so pull this into your org and get cracking! Of note: The test code assumes that you have no record types for the Solution object. If you do, you may need to remove that test method. Badges The Code The class and test class are found in this folder . Feel free to copy/paste directly into your org. Documentation ApexDox (generated with ApexDox ) Installation Clone this repository and run . scripts/orginit.sh to set up a scratch org with the classes installed and a single Account Record Type. To set up a scratch org without creating a Record Type, run .scripts/orginit-norecordtypes.sh Changelog 2023-08-18 Add methods to get default RecordTypeId, handling situation where no RT is on the Profile but at least one is avaialble via Permission Set. Add test methods against Account and Solution objects, as we assume Solution has no defined record types.(Change for your org if you have them.) 2022-03-29 BREAKING CHANGE: Replaced \"DeveloperName\" with \"DevName\" in all method names. Update your code to refer to the new methods. 2022-03-29 Add maps Id => Name and Id => DeveloperName for ease of use when wanting to refer to a record type by Id without including the object, since Id is globally unique 2022-01-19 Initial Release"
+ "text": "Home Record Types Utilities Written by Evan Callahan, copyright(c) 2010 Groundwire This program is released under the GNU General Public License. http://www.gnu.org/licenses/ This class is meant to allow for access to Record Type information from within other classes. It is called statically, and therefore will supply the same information to all calls made from within one transaction, or set of trigger calls. This is beneficial because this info should be the same for all calls in a transaction, and by calling it statically we reduce the calls that are made, making the total transaction more efficient. Updated by David Schach, copyright(c) 2021 X-Squared on Demand This class allows for easy, readable access to Record Type information from other classes. Usage recommendation: Always use DeveloperName instead of Name, as this is more likely to be hard-coded in places, while the Name is actually a label and may change(especially due to user language). Record-Types This is a project based on work by Evan Callahan (formerly of Groundwire, and now at Salesforce) who wrote this class (Repo has been deleted. Sadface.) a long time ago to reduce the number of describe calls required to work with Record Types. I've updated the project(by pulling test code out of the main class - that's how old it was!) and have added some additional methods. The included test class has 100% coverage, so pull this into your org and get cracking! Of note: The test code assumes that you have no record types for the Solution object. If you do, you may need to remove that test method. Badges The Code The class and test class are found in this folder . Feel free to copy/paste directly into your org. Documentation ApexDox (generated with ApexDox ) Installation Clone this repository and run . scripts/orginit.sh to set up a scratch org with the classes installed and a single Account Record Type. To set up a scratch org without creating a Record Type, run .scripts/orginit-norecordtypes.sh Changelog 2023-08-18 Add methods to get default RecordTypeId, handling situation where no RT is on the Profile but at least one is avaialble via Permission Set. Add test methods against Account and Solution objects, as we assume Solution has no defined record types.(Change for your org if you have them.) 2022-03-29 BREAKING CHANGE: Replaced \"DeveloperName\" with \"DevName\" in all method names. Update your code to refer to the new methods. 2022-03-29 Add maps Id => Name and Id => DeveloperName for ease of use when wanting to refer to a record type by Id without including the object, since Id is globally unique 2022-01-19 Initial Release Most Common Methods These are the most common methods to be used. They are the fastest ways to get a Record Type Id from an object name and the developer name, for example. There are soem overloaded methods included for historical purposes(the ones that accept a Record Type Id and an object name and return the developer name). While the object name is, technically, optional, that method is faster because it does not require memoizing a SOQL query. Parameters / Output Id Name DeveloperName objectName, recordTypeName getRecordTypeIdFromName objectName, recordTypeName getRecordTypeDevNameFromName objectName, recordTypeDevName getRecordTypeFromDevName objectName, recordTypeDevName getRecordTypeNameFromDevName objectName, recordTypeDevName getRecordTypeIdFromDevName objectName, recordTypeId getRecordTypeNameFromId objectName, recordTypeId getRecordTypeDevNameFromId recordTypeId getRecordTypeNameFromId recordTypeId getRecordTypeDevNameFromId Less Common Methods These methods are used less often but may be useful. The most useful of these are the SelectList generators for Visualforce. However, if you are using LWC, you may prefer to use some of the other methods and to parse the returned list of RecordTypeInfo items yourself. Parameters / Output Schema.RecordTypeInfo Map(String, Id) SelectList Set
objectName, recordTypeId getRecordTypeFromId objectName, Set getRecordTypeIdSetFromDevNames objectName getRecordTypeDevNameIdMap objectName getRecordTypeNameIdMap objectName getAvailableRecordTypeDevNameIdMap objectName getAvailableRecordTypeNameIdMap objectName getRecordTypesForSelectList objectName getAllRecordTypesForSelectList objectName getStringRecordTypesForSelectList"
},
{
"title": "changelog",
@@ -12,12 +12,12 @@ export default [
{
"title": "RecordTypesHome",
"fileName": "RecordTypesHome.html",
- "text": "Record Types Utilities Written by Evan Callahan, copyright(c) 2010 Groundwire This program is released under the GNU General Public License. http://www.gnu.org/licenses/ This class is meant to allow for access to Record Type information from within other classes. It is called statically, and therefore will supply the same information to all calls made from within one transaction, or set of trigger calls. This is beneficial because this info should be the same for all calls in a transaction, and by calling it statically we reduce the calls that are made, making the total transaction more efficient. Updated by David Schach, copyright(c) 2021 X-Squared on Demand This class is allows for easy, readable access to Record Type information from other classes. Usage recommendation: Always use DeveloperName instead of Name, as this is more likely to be hard-coded in places, while the Name is actually a label and may change(especially due to user language)."
+ "text": "RecordTypes Record Types Utilities Written by Evan Callahan, copyright(c) 2010 Groundwire This program is released under the GNU General Public License. http://www.gnu.org/licenses/ This class is meant to allow for access to Record Type information from within other classes. It is called statically, and therefore will supply the same information to all calls made from within one transaction, or set of trigger calls. This is beneficial because this info should be the same for all calls in a transaction, and by calling it statically we reduce the calls that are made, making the total transaction more efficient. Updated by David Schach, copyright(c) 2021 X-Squared on Demand This class allows for easy, readable access to Record Type information from other classes. Usage recommendation: Always use DeveloperName instead of Name, as this is more likely to be hard-coded in places, while the Name is actually a label and may change(especially due to user language)."
},
{
"title": "RecordTypes",
"fileName": "RecordTypes.html",
- "text": "RecordTypes This class is allows for easy, readable access to Record Type information from other classes. Written by Evan Callahan, copyright(c) 2010 Groundwire Updated by David Schach, copyright(c) 2021 X-Squared on Demand This program is released under the GNU General Public License. http://www.gnu.org/licenses/ This class is meant to allow for access to Record Type information from within other classes. It is called statically, and therefore will supply the same information to all calls made from within one transaction, or set of trigger calls. This is beneficial because this info should be the same for all calls in a transaction, and by calling it statically we reduce the calls that are made, making the total transaction more efficient. Usage recommendation: Always use DeveloperName instead of Name, as this is more likely to be hard-coded in places, while the Name is actually a label and may change(especially due to user language). Signature global inherited sharing class RecordTypes See RecordTypesTest Author Evan Callahan , Groundwire Since 2010 Author David Schach , X-Squared on Demand Since 2021 Author Nicolas Vasquez, Globant Since 2022 RecordTypes Properties Name Signature Description allRecordTypes private static Map> allRecordTypes map of all Record Types by sObject name, including inactive and unavailable availableRecordTypesMap private static Map> availableRecordTypesMap List of available(to the running user) Record Type Info sObjects defaultRecordTypeIds private static Map defaultRecordTypeIds Map of default Record Type Ids for the running user defaultRecordTypes private static Map defaultRecordTypes Map of object name to the default Schema.RecordTypeInfo object for that object gd private static Map gd Global schema describe recordTypesByDevName private static Map> recordTypesByDevName Map of Record Types by sObject name, then by DeveloperName recordTypesById private static Map> recordTypesById Map of Record Types by sObject name, then by Id recordTypesByName private static Map> recordTypesByName Map of Record Types by sObject name, then by Name recordTypesIdMap private static Map recordTypesIdMap Lazy-loaded, memoized map of queried RecordType records by Id RecordTypes Methods clearMapsInTest() If we are running a test, clear sObject maps. We do this to avoid using @testVisible on the maps 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 the RecordType Name displayed and the RecordType Id as the value getAvailableRecordTypeDevNameIdMap(objectName) Gives a map of all available(to the running user) RecordTypeId s by developername for an sObject getAvailableRecordTypeNameIdMap(objectName) Gives a map of all available(to the running user) RecordTypeId s by name 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 getRecordType(objectName, recordTypeId) Given an sObject and RecordType Id, return the RecordType object 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 RecordType.DeveloperName methods instead getRecordTypeDevNameIdMap(objectName) Gives a map of all record type IDs by DeveloperName for an sObject getRecordTypeFromDevName(objectName, recordTypeDevName) Given an sObject and RecordType DeveloperName, return the RecordType Id 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 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 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. getRecordTypesForSelectList(objectName) Make a Visualforce picklist with the RecordType Name displayed and the RecordType Id as the value getStringRecordTypesForSelectList(objectName) Make a Visualforce picklist with the RecordType Name displayed and the RecordType Name as the value clearMapsInTest() If we are running a test, clear sObject maps. We do this to avoid using @testVisible on the maps This is private and testvisible so it cannot be called in production code context Signature @testVisible private static void clearMapsInTest() 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 Signature private static void fillMapsForObject(String objectName) Parameters objectName Type: String SObject name(with __c if custom, etc) Author David Schach getAllRecordTypesForSelectList(objectName) Make a Visualforce picklist with the RecordType Name displayed and the RecordType Id as the value Signature global static List getAllRecordTypesForSelectList(String objectName) Parameters objectName Type: String SObject name(with __c if custom, etc) Returns List Visualforce SelectOption list Author David Schach getAvailableRecordTypeDevNameIdMap(objectName) Gives a map of all available(to the running user) RecordTypeId s by developername for an sObject Signature global static Map getAvailableRecordTypeDevNameIdMap(String objectName) Parameters objectName Type: String SObject name(with __c if custom, etc) Returns Map Map Authors Nicolas Vasquez, David Schach Since 2023 Use available record types map getAvailableRecordTypeNameIdMap(objectName) Gives a map of all available(to the running user) RecordTypeId s by name for an sObject Signature global static Map getAvailableRecordTypeNameIdMap(String objectName) Parameters objectName Type: String SObject name(with __c if custom, etc) Returns Map Map Authors Nicolas Vasquez, David Schach Since 2023 Use available record types map getDefaultRecordType(objectName) Given an sObject Name, return the default Record Type Id for the running user Signature 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 getDefaultRecordTypeDevName(objectName) 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 getDefaultRecordTypeId(objectName) 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 getDefaultRecordTypeName(objectName) 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 getRecordType(objectName, recordTypeId) Given an sObject and RecordType Id, return the RecordType object Signature global static Schema.RecordTypeInfo getRecordType(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 David Schach getRecordTypeDevNameFromId(objectName, recordTypeId) 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 David Schach 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 Signature global static String getRecordTypeDevNameFromId(Id recordTypeId) Parameters recordTypeId Type: Id RecordTypeId Returns String Record Type Name See getRecordTypeDevNameFromId Author David Schach Since 2022-03-29 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 RecordType.DeveloperName methods 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 David Schach Example RecordTypes.getRecordTypeDevNameFromName('Account','Person Account') getRecordTypeDevNameIdMap(objectName) Gives a map of all record type IDs by DeveloperName for an sObject Signature global static Map getRecordTypeDevNameIdMap(String objectName) Parameters objectName Type: String SObject name(with __c if custom, etc) Returns Map Map Author David Schach getRecordTypeFromDevName(objectName, recordTypeDevName) 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 David Schach Example RecordTypes.getRecordTypeFromDevName('Account','Person_Account') getRecordTypeFromId(objectName, recordTypeId) 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 David Schach 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 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 David Schach getRecordTypeIdFromDevName(objectName, recordTypeDevName) 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 David Schach Example RecordTypes.getRecordTypeIdFromDevName('Account','Person_Account') 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 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 David Schach Example RecordTypes.getRecordTypeIdFromName('Account','Person Account') getRecordTypeIdSetFromDevNames(objectName, recordTypeDevNameSet) Gives a set of RecordType Ids from an sObject and a set of RecordType DeveloperNames Signature global static Set getRecordTypeIdSetFromDevNames(String objectName, Set recordTypeDevNameSet) Parameters objectName Type: String SObject name(with __c if custom, etc) recordTypeDevNameSet Type: Set Set of DeveloperNames Returns Set All RecordType IDs for a given sObject Author David Schach Example Set rtNames = new Set {'Person_Account', 'Customer'}; getRecordTypeIdSetFromDevNames('Account', rtNames); getRecordTypeNameFromDevName(objectName, recordTypeDevName) 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 David Schach Example RecordTypes.getRecordTypeNameFromDevName('Account','Person_Account') getRecordTypeNameFromId(objectName, recordTypeId) 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 David Schach getRecordTypeNameFromId(recordTypeId) 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 David Schach Since 2022-03-29 getRecordTypeNameIdMap(objectName) Gives a map of all RecordType IDs by name for an sObject Signature global static Map getRecordTypeNameIdMap(String objectName) Parameters objectName Type: String SObject name(with __c if custom, etc) Returns Map Map Author Evan Callahan 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. Signature global static List getRecordTypesForObject(String objectName) Parameters objectName Type: String SObject name(with __c if custom, etc) Returns List List of all record types for the object(active and inactive) Author David Schach getRecordTypesForSelectList(objectName) Make a Visualforce picklist with the RecordType Name displayed and the RecordType Id as the value Signature global static List getRecordTypesForSelectList(String objectName) Parameters objectName Type: String SObject name(with __c if custom, etc) Returns List Visualforce SelectOption list Author Evan Callahan getStringRecordTypesForSelectList(objectName) Make a Visualforce picklist with the RecordType Name displayed and the RecordType Name as the value Signature global static List getStringRecordTypesForSelectList(String objectName) Parameters objectName Type: String SObject name(with __c if custom, etc) Returns List Visualforce SelectOption list Author Evan Callahan"
+ "text": "RecordTypes This class is allows for easy, readable access to Record Type information from other classes. Written by Evan Callahan, copyright(c) 2010 Groundwire Updated by David Schach, copyright(c) 2021 X-Squared on Demand This program is released under the GNU General Public License. http://www.gnu.org/licenses/ This class is meant to allow for access to Record Type information from within other classes. It is called statically, and therefore will supply the same information to all calls made from within one transaction, or set of trigger calls. This is beneficial because this info should be the same for all calls in a transaction, and by calling it statically we reduce the calls that are made, making the total transaction more efficient. Usage recommendation: Always use DeveloperName instead of Name, as this is more likely to be hard-coded in places, while the Name is actually a label and may change(especially due to user language). An easy-to-read table with the various methods, their inputs, and their outputs is available at RecordTypesHome Signature global inherited sharing class RecordTypes See RecordTypesTest Author Evan Callahan , Groundwire Since 2010 Author David Schach , X-Squared on Demand Since 2021 Author Nicolas Vasquez, Globant Since 2022 RecordTypes Properties Name Signature Description allRecordTypes private static Map> allRecordTypes map of all Record Types by sObject name, including inactive and unavailable availableRecordTypesMap private static Map> availableRecordTypesMap List of available(to the running user) Record Type Info sObjects defaultRecordTypeIds private static Map defaultRecordTypeIds Map of default Record Type Ids for the running user defaultRecordTypes private static Map defaultRecordTypes Map of object name to the default Schema.RecordTypeInfo object for that object gd private static Map gd Global schema describe recordTypesByDevName private static Map> recordTypesByDevName Map of Record Types by sObject name, then by DeveloperName recordTypesById private static Map> recordTypesById Map of Record Types by sObject name, then by Id recordTypesByName private static Map> recordTypesByName Map of Record Types by sObject name, then by Name recordTypesIdMap private static Map recordTypesIdMap Lazy-loaded, memoized map of queried RecordType records by Id RecordTypes Methods clearMapsInTest() If we are running a test, clear sObject maps. We do this to avoid using @testVisible on the maps 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 getAvailableRecordTypeDevNameIdMap(objectName) Gives a map of all available(to the running user) RecordTypeId s by developername for an sObject getAvailableRecordTypeNameIdMap(objectName) Gives a map of all available(to the running user) RecordTypeId s by name 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 RecordType.DeveloperName methods instead getRecordTypeDevNameIdMap(objectName) Gives a map of all record type IDs by DeveloperName for an sObject getRecordTypeFromDevName(objectName, recordTypeDevName) Given an sObject and RecordType DeveloperName, return the RecordType Id 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 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 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. getRecordTypesForSelectList(objectName) Make a Visualforce picklist of all available Record Types with the RecordType Name displayed and the RecordType Id as the value getStringRecordTypesForSelectList(objectName) Make a Visualforce picklist with the RecordType Name displayed and the RecordType Name as the value clearMapsInTest() If we are running a test, clear sObject maps. We do this to avoid using @testVisible on the maps This is private and testvisible so it cannot be called in production code context Signature @testVisible private static void clearMapsInTest() 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 Signature private static void fillMapsForObject(String objectName) Parameters objectName Type: String SObject name(with __c if custom, etc) Author David Schach 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 Signature global static List getAllRecordTypesForSelectList(String objectName) Parameters objectName Type: String SObject name(with __c if custom, etc) Returns List Visualforce SelectOption list Author David Schach getAvailableRecordTypeDevNameIdMap(objectName) Gives a map of all available(to the running user) RecordTypeId s by developername for an sObject Signature global static Map getAvailableRecordTypeDevNameIdMap(String objectName) Parameters objectName Type: String SObject name(with __c if custom, etc) Returns Map Map Authors Nicolas Vasquez, David Schach Since 2023 Use available record types map getAvailableRecordTypeNameIdMap(objectName) Gives a map of all available(to the running user) RecordTypeId s by name for an sObject Signature global static Map getAvailableRecordTypeNameIdMap(String objectName) Parameters objectName Type: String SObject name(with __c if custom, etc) Returns Map Map Authors Nicolas Vasquez, David Schach Since 2023 Use available record types map getDefaultRecordType(objectName) 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 getDefaultRecordTypeDevName(objectName) 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 getDefaultRecordTypeId(objectName) 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 getDefaultRecordTypeName(objectName) 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 getRecordTypeDevNameFromId(objectName, recordTypeId) 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 David Schach 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 Signature global static String getRecordTypeDevNameFromId(Id recordTypeId) Parameters recordTypeId Type: Id RecordTypeId Returns String Record Type Name See getRecordTypeDevNameFromId Author David Schach Since 2022-03-29 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 RecordType.DeveloperName methods 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 David Schach Example RecordTypes.getRecordTypeDevNameFromName('Account','Person Account') getRecordTypeDevNameIdMap(objectName) Gives a map of all record type IDs by DeveloperName for an sObject Signature global static Map getRecordTypeDevNameIdMap(String objectName) Parameters objectName Type: String SObject name(with __c if custom, etc) Returns Map Map Author David Schach getRecordTypeFromDevName(objectName, recordTypeDevName) 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 David Schach Example RecordTypes.getRecordTypeFromDevName('Account','Person_Account') getRecordTypeFromId(objectName, recordTypeId) 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 David Schach 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 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 David Schach getRecordTypeIdFromDevName(objectName, recordTypeDevName) 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 David Schach Example RecordTypes.getRecordTypeIdFromDevName('Account','Person_Account') 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 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 David Schach Example RecordTypes.getRecordTypeIdFromName('Account','Person Account') getRecordTypeIdSetFromDevNames(objectName, recordTypeDevNameSet) Gives a set of RecordType Ids from an sObject and a set of RecordType DeveloperNames Signature global static Set getRecordTypeIdSetFromDevNames(String objectName, Set recordTypeDevNameSet) Parameters objectName Type: String SObject name(with __c if custom, etc) recordTypeDevNameSet Type: Set Set of DeveloperNames Returns Set All RecordType IDs for a given sObject Author David Schach Example Set rtNames = new Set {'Person_Account', 'Customer'}; getRecordTypeIdSetFromDevNames('Account', rtNames); getRecordTypeNameFromDevName(objectName, recordTypeDevName) 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 David Schach Example RecordTypes.getRecordTypeNameFromDevName('Account','Person_Account') getRecordTypeNameFromId(objectName, recordTypeId) 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 David Schach getRecordTypeNameFromId(recordTypeId) 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 David Schach Since 2022-03-29 getRecordTypeNameIdMap(objectName) Gives a map of all RecordType IDs by name for an sObject Signature global static Map getRecordTypeNameIdMap(String objectName) Parameters objectName Type: String SObject name(with __c if custom, etc) Returns Map Map Author Evan Callahan 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. Signature global static List getRecordTypesForObject(String objectName) Parameters objectName Type: String SObject name(with __c if custom, etc) Returns List List of all record types for the object(active and inactive) Author David Schach getRecordTypesForSelectList(objectName) Make a Visualforce picklist of all available Record Types with the RecordType Name displayed and the RecordType Id as the value Signature global static List getRecordTypesForSelectList(String objectName) Parameters objectName Type: String SObject name(with __c if custom, etc) Returns List Visualforce SelectOption list Author Evan Callahan Example RecordTypes.getRecordTypesForSelectList('Account') System.SelectOption[value=\"\", label=\"Available\", disabled=\"false\"] System.SelectOption[value=\"\", label=\"Default\", disabled=\"false\"] getStringRecordTypesForSelectList(objectName) Make a Visualforce picklist with the RecordType Name displayed and the RecordType Name as the value Signature global static List getStringRecordTypesForSelectList(String objectName) Parameters objectName Type: String SObject name(with __c if custom, etc) Returns List Visualforce SelectOption list Author Evan Callahan"
},
{
"title": "RecordTypesTest",
diff --git a/docs/changelog.html b/docs/changelog.html
index 7f57a35..29124e1 100644
--- a/docs/changelog.html
+++ b/docs/changelog.html
@@ -39,7 +39,7 @@
diff --git a/docs/index.html b/docs/index.html
index 6a23c49..cfb3b6d 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -39,7 +39,7 @@
@@ -88,31 +88,30 @@ Record Types Utilities
This class is meant to allow for access to Record Type information from within other classes.
- It is called statically, and therefore will supply the same information to all calls made from within one transaction, or set of trigger calls. This is
- beneficial because this info should be the same for all calls in a transaction, and by calling it statically we reduce the calls that are made, making the
- total transaction more efficient.
+ It is called statically, and therefore will supply the same information to all calls made from within one transaction, or set of trigger calls. This is beneficial because this
+ info should be the same for all calls in a transaction, and by calling it statically we reduce the calls that are made, making the total transaction more efficient.
Updated by David Schach, copyright (c) 2021 X-Squared on Demand
- This class is allows for easy, readable access to Record Type information from other classes.
+ This class allows for easy, readable access to Record Type information from other classes.
- Usage recommendation: Always use DeveloperName instead of Name, as this is more likely to be hard-coded in places, while the Name is actually a label and may
- change (especially due to user language).
+ Usage recommendation: Always use DeveloperName instead of Name, as this is more likely to be hard-coded in places, while the Name is actually a label and may change (especially
+ due to user language).
Record-Types
This is a project based on work by Evan Callahan (formerly of Groundwire, and now at Salesforce) who wrote this class (Repo has been deleted. Sadface.) a long time ago to reduce the number of describe calls required to work with Record Types.
- I've updated the project (by pulling test code out of the main class - that's how old it was!) and have added some additional methods.
- The included test class has 100% coverage, so pull this into your org and get cracking!
+ I've updated the project (by pulling test code out of the main class - that's how old it was!) and have added some additional methods. The included test class has 100% coverage, so pull this into your org and get cracking!
Of note: The test code assumes that you have no record types for the Solution object. If you do, you may need to remove that test method.
Badges
+
The Code
The class and test class are found in this folder. Feel free to copy/paste directly into your org.
@@ -143,6 +142,195 @@ Changelog
+
+ Most Common Methods
+
+ These are the most common methods to be used. They are the fastest ways to get a Record Type Id from an object name and the developer name, for example.
+
+ There are soem overloaded methods included for historical purposes (the ones that accept a Record Type Id and an object name and return the developer name).
+ While the object name is, technically, optional, that method is faster because it does not require memoizing a SOQL query.
+
+
+
+ Less Common Methods
+
+ These methods are used less often but may be useful.
+
+ The most useful of these are the SelectList generators for Visualforce. However, if you are using LWC, you may prefer to use some of the other methods and to
+ parse the returned list of RecordTypeInfo items yourself.
+
+
diff --git a/force-app/main/default/classes/RecordTypes.cls b/force-app/main/default/classes/RecordTypes.cls
index 4b3def1..e3cd6e5 100644
--- a/force-app/main/default/classes/RecordTypes.cls
+++ b/force-app/main/default/classes/RecordTypes.cls
@@ -16,6 +16,9 @@
*
*
Usage recommendation: Always use DeveloperName instead of Name, as this is more likely to be
* hard-coded in places, while the Name is actually a label and may change (especially due to user language).
+ *
+ * An easy-to-read table with the various methods, their inputs, and their outputs is available at
+ * {@link [RecordTypesHome](./RecordTypesHomt.html)}
*
* @author {@link [Evan Callahan](https://github.com/groundwired)}, Groundwire
* @since 2010
@@ -24,6 +27,7 @@
* @author Nicolas Vasquez, Globant
* @since 2022
* @group RecordTypes
+ * @group-content doc-assets/RecordTypesHome.html
* @see RecordTypesTest
*/
global inherited sharing class RecordTypes {
@@ -376,28 +380,6 @@ global inherited sharing class RecordTypes {
return getRecordTypeFromId(objectName, recordTypeId)?.getDeveloperName();
}
- /**
- * @description Given an sObject and `RecordType` Id, return the `RecordType` object
- * @author {@link [David Schach](https://github.com/dschach)}
- * @param objectName SObject name (with __c if custom, etc)
- * @param recordTypeId RecordType Id
- * @return `Schema.RecordTypeInfo` RecordTypeInfo object
- */
- global static Schema.RecordTypeInfo getRecordType(String objectName, Id recordTypeId) {
- // make sure we have this sObject's record types mapped
- if (!recordTypesById.containsKey(objectName)) {
- fillMapsForObject(objectName);
- }
-
- // now grab and return the requested object
- Map
rtMap = recordTypesById.get(objectName);
- if (rtMap != null && rtMap.containsKey(RecordTypeId)) {
- return rtMap.get(recordTypeId);
- } else {
- return null;
- }
- }
-
/**
* @description Gives a set of `RecordType` Ids from an sObject and a set of `RecordType` DeveloperNames
* @author {@link [David Schach](https://github.com/dschach)}
@@ -569,10 +551,16 @@ global inherited sharing class RecordTypes {
}
/**
- * @description Make a Visualforce picklist with the `RecordType` Name displayed and the `RecordType` Id as the value
+ * @description Make a Visualforce picklist of all available Record Types with the `RecordType` Name
+ * displayed and the `RecordType` Id as the value
* @author Evan Callahan
* @param objectName SObject name (with __c if custom, etc)
* @return `List` Visualforce SelectOption list
+ * @example
+ * RecordTypes.getRecordTypesForSelectList('Account')
+ *
+ * System.SelectOption[value="", label="Available", disabled="false"]
+ * System.SelectOption[value="", label="Default", disabled="false"]
*/
global static List getRecordTypesForSelectList(String objectName) {
List recordTypesOptions = new List();
@@ -587,7 +575,8 @@ global inherited sharing class RecordTypes {
}
/**
- * @description Make a Visualforce picklist with the `RecordType` Name displayed and the `RecordType` Id as the value
+ * @description 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
* @author {@link [David Schach](https://github.com/dschach)}
* @param objectName SObject name (with __c if custom, etc)
* @return `List` Visualforce SelectOption list
diff --git a/force-app/main/default/classes/RecordTypesTest.cls b/force-app/main/default/classes/RecordTypesTest.cls
index 23f5b6e..152bd3e 100644
--- a/force-app/main/default/classes/RecordTypesTest.cls
+++ b/force-app/main/default/classes/RecordTypesTest.cls
@@ -21,7 +21,6 @@ private class RecordTypesTest {
//Test with Bogus object
Assert.isNull(RecordTypes.getRecordTypesForObject('Bogus'), 'Bogus object should not exist');
- Assert.isNull(RecordTypes.getRecordType('Bogus', null), 'Bogus object should not exist');
Assert.isNull(RecordTypes.getRecordTypeDevNameFromId(null), 'Nonexistent RecordType');
Assert.isNull(RecordTypes.getRecordTypeNameFromId(null), 'Nonexistent RecordType');
@@ -152,7 +151,7 @@ private class RecordTypesTest {
RecordType activeRT = accountRecordTypes[0];
- Schema.RecordTypeInfo rti = RecordTypes.getRecordType('Account', activeRT.Id);
+ Schema.RecordTypeInfo rti = RecordTypes.getRecordTypeFromId('Account', activeRT.Id);
Assert.areNotEqual(null, RecordTypes.getRecordTypeDevNameFromId(activeRT.Id), 'We should have had an Account RecordType');
Assert.areNotEqual(null, RecordTypes.getRecordTypeNameFromId(activeRT.Id), 'We should have had an Account RecordType');
@@ -232,8 +231,7 @@ private class RecordTypesTest {
RecordType activeRT = accountRecordTypes[0];
- Schema.RecordTypeInfo rti = RecordTypes.getRecordType('Contact', activeRT.Id);
-
+ Schema.RecordTypeInfo rti = RecordTypes.getRecordTypeFromId('Contact', activeRT.Id);
Assert.areNotEqual(null, RecordTypes.getRecordTypeDevNameFromId(activeRT.Id), 'We should have had an Contact RecordType');
Assert.areNotEqual(null, RecordTypes.getRecordTypeNameFromId(activeRT.Id), 'We should have had an Contact RecordType');