Skip to content

Commit

Permalink
feat: overload get RT from Id (#79)
Browse files Browse the repository at this point in the history
* feat: overload getRecordTypeFromId to take only Id

* chore: adjust methods table

* methods table

* fix methods table

* URL to docs

* update readme

* ready to try csplit

* docs: update ApexDox, including method table

* test: add test coverage for overloaded method
  • Loading branch information
dschach authored Sep 17, 2023
1 parent a3cded8 commit 1344b75
Show file tree
Hide file tree
Showing 16 changed files with 633 additions and 571 deletions.
65 changes: 61 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,70 @@ The class and test class are found in this [folder](/force-app/main/default/clas

## [Changelog](./CHANGELOG.md)

- 2023-08-18
- 2023-09 Overload getRecordTypeFromId so it doesn't require a SobjectType string

- 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 (c) 2010 Groundwire

- This program is released under the [GNU General Public License](./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

- 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](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.

| 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

- 2022-03-29 BREAKING CHANGE: Replaced "DeveloperName" with "DevName" in all method names. Update your code to refer to the new methods.
These methods are used less often but may be useful.

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

- 2022-01-19 Initial Release
| Parameters / Output | Schema.RecordTypeInfo | Map(String, Id) | SelectList | Set<Id> |
| ---------------------------------------- | --------------------- | ---------------------------------- | --------------------------------- | ------------------------------ |
| recordTypeId | getRecordTypeFromId | | | |
| objectName, recordTypeId | getRecordTypeFromId | | | |
| objectName, Set<recordTypeDevName> | | | | getRecordTypeIdSetFromDevNames |
| objectName | | getRecordTypeDevNameIdMap | | |
| objectName | | getRecordTypeNameIdMap | | |
| objectName | | getAvailableRecordTypeDevNameIdMap | | |
| objectName | | getAvailableRecordTypeNameIdMap | | |
| objectName | | | getRecordTypesForSelectList | |
| objectName | | | getAllRecordTypesForSelectList | |
| objectName | | | getStringRecordTypesForSelectList | |
3 changes: 1 addition & 2 deletions apexdox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ engine:
homePagePath: "${workspaceFolder}/doc-assets/main.html"
pages:
- "${workspaceFolder}/doc-assets/changelog.html"

#- "${workspaceFolder}/doc-assets/RecordTypesHome.html"
assets:
- "${workspaceFolder}/doc-assets/logo.png"
- "${workspaceFolder}/doc-assets/favicon.png"
Expand All @@ -30,7 +30,6 @@ engine:
- "${workspaceFolder}/doc-assets/index.css"
- "${workspaceFolder}/doc-assets/highlight.js"
- "${workspaceFolder}/doc-assets/index.js"
#- "${workspaceFolder}/doc-assets/RecordTypesHome.html"

port: 8080
docblock:
Expand Down
23 changes: 0 additions & 23 deletions doc-assets/RecordTypesHome.html

This file was deleted.

Loading

0 comments on commit 1344b75

Please sign in to comment.