GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - dschach/record-types: Record Type utility class enabling quick, efficient retrieval of RecordTypeId from SObject name and a Record Type Name or DeveloperName. Built on work by Evan Callahan.

BranchesTags
Open more actions menu

Latest commit

 

History

357 Commits
357 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
.husky
.husky
 
 
.vscode
.vscode
 
 
config
config
 
 
doc-assets
doc-assets
 
 
docs
docs
 
 
force-app/main/default/classes
force-app/main/default/classes
 
 
media
media
 
 
pmd
pmd
 
 
scripts
scripts
 
 
unpackaged/main/default
unpackaged/main/default
 
 
.forceignore
.forceignore
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
.prettierignore
.prettierignore
 
 
.prettierrc.mjs
.prettierrc.mjs
 
 
.release-please-manifest.json
.release-please-manifest.json
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
apexdox.yml
apexdox.yml
 
 
code-analyzer.yml
code-analyzer.yml
 
 
jest.config.js
jest.config.js
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
release-please-config.json
release-please-config.json
 
 
sfdx-project.json
sfdx-project.json
 
 

Repository files navigation

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 unpackaged test class assumes that you have no record types for the Solution object. If you do, you may need to remove that test method.

Dependabot Known Vulnerabilities codecov On Push Scratch Org Tests Salesforce API Version Release GitHub License

Twitter GitHub

The Code

The class and test class are found in this folder. Feel free to copy/paste directly into your org.

Features

Given combinations of an sObject name, Record Type name, Record Type developer name, and Record Type Id, this class will let you return the other possible parameters. Give it an sObject name and a Record Type developer name, and get the Record Type Id.

The main purpose is to minimize describe calls, which will speed up your code.

Documentation

Documentation (generated with ApexDox)

Package Installation

Deploy to Salesforce Deploy to Salesforce Sandbox

Installation (with VCS)

Clone this repository and run bash 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 bash scripts/orginit-norecordtypes.sh

Changelog

  • 2026-11

    • Update to API 68.0
    • Faster tests: no global describe, and shared assertions instead of duplicated test methods
    • Test classes declare the class they test with @IsTest(testFor=...)
    • Cover the default and available Record Type paths with a test-only profile that makes the Default Account Record Type the default
    • Run PMD from one reusable workflow on pull requests and on every push to main, and upload code coverage on every push to main
  • 2026-10

    • Install Salesforce Code Analyzer and update PMD ruleset
  • 2024-03

    • All methods are now case-insensitive
    • Dynamic describe methods remove need for global describe (faster code!)
    • Move Solution tests - does not increase coverage - to unpackaged test class
  • 2024-02

    • Enhance SelectList methods
    • Update to API 60.0
    • Increase code coverage and test cases
  • 2023-09

    • Overload getRecordTypeFromId so it doesn't require a SobjectType string
    • Release unlocked package
  • 2023-08

    • 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.)
    • Include table of all methods on documentation site
  • 2022-03

    • BREAKING CHANGE: Replaced "DeveloperName" with "DevName" in all method names. Update your code to refer to the new methods.
  • 2022-03

    • 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

    • Initial Release

Code Header

Written by Evan Callahan, copyright © 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 © X-Squared on Demand

  • 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).

Library Methods

(Full documentation at https://dschach.github.io/record-types)

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 some 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.

GivenReturnsMethod
objectName, recordTypeNameIdgetRecordTypeIdFromName
objectName, recordTypeNameDeveloperNamegetRecordTypeDevNameFromName
objectName, recordTypeDevNameIdgetRecordTypeIdFromDevName most used
objectName, recordTypeDevNameNamegetRecordTypeNameFromDevName
objectName, recordTypeIdNamegetRecordTypeNameFromId
objectName, recordTypeIdDeveloperNamegetRecordTypeDevNameFromId
recordTypeIdNamegetRecordTypeNameFromId
recordTypeIdDeveloperNamegetRecordTypeDevNameFromId

Helper Methods

These methods check record types available to the current/running user.

GivenReturnsMethod
objectName, recordTypeDevNameBooleanisRecordTypeAvailable
objectName, recordTypeDevNameBooleanisRecordTypeDefault

Default Record Type Methods

These methods return the default Record Type for the current/running user.

GivenReturnsMethod
objectNameSchema.RecordTypeInfogetDefaultRecordType
objectNameId (null if the default is Master)getDefaultRecordTypeId
objectNameName (Master if the default is Master)getDefaultRecordTypeName
objectNameDeveloperName (Master if the default is Master)getDefaultRecordTypeDevName

Less Common Methods

The most useful of these may be 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.

GivenReturnsMethod
RecordTypeInfo
recordTypeIdSchema.RecordTypeInfogetRecordTypeFromId
objectName, recordTypeIdSchema.RecordTypeInfogetRecordTypeFromId
objectName, recordTypeNameSchema.RecordTypeInfogetRecordTypeFromName
objectName, recordTypeDevNameSchema.RecordTypeInfogetRecordTypeFromDevName
objectNameList<Schema.RecordTypeInfo>getRecordTypesForObject
Sets of Ids
objectNameSet<Id> of the available Record TypesgetAvailableRecordTypesIdSet
objectName, Set<recordTypeDevName>Set<Id>getRecordTypeIdSetFromDevNames
Maps of Ids
objectNameMap<String, Id> by DeveloperNamegetRecordTypeDevNameIdMap
objectNameMap<String, Id> by NamegetRecordTypeNameIdMap
objectNameMap<String, Id> by DeveloperName, available Record Types onlygetAvailableRecordTypeDevNameIdMap
objectNameMap<String, Id> by Name, available Record Types onlygetAvailableRecordTypeNameIdMap
Visualforce select lists
objectNameList<SelectOption> of all Record Types, unavailable ones disabledgetAllRecordTypesForSelectList
objectName, disableUnavailableList<SelectOption> of all Record Types, disabling the unavailable ones only if truegetAllRecordTypesForSelectList
objectNameList<SelectOption> of the available Record TypesgetAvailableRecordTypesForSelectList
objectNameList<SelectOption> with the Name as the valuegetStringRecordTypesForSelectList

About

Record Type utility class enabling quick, efficient retrieval of RecordTypeId from SObject name and a Record Type Name or DeveloperName. Built on work by Evan Callahan.

dschach.github.io/record-types/

Topics

apexrecordtypesalesforcesalesforcedxutilityutility-classes

Resources

Readme
GPL-3.0 license
Activity

Stars

2 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.