Skip to content

Commit

Permalink
fix: remove redundant methods, update docs (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschach authored Aug 19, 2023
1 parent ee2d5de commit 3487d30
Show file tree
Hide file tree
Showing 15 changed files with 876 additions and 206 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

This is a project based on work by [Evan Callahan](https://github.com/groundwired) (formerly of Groundwire, and now at Salesforce) who wrote [this class](https://github.com/SalesforceFoundation/JenkinsTesting/blob/master/src/classes/RecordTypes.cls) (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.

Expand Down
3 changes: 2 additions & 1 deletion 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,6 +30,7 @@ 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
2 changes: 1 addition & 1 deletion doc-assets/RecordTypesHome.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h2>Additional/Changed Header</h2> -->
<p>
Updated by David Schach, copyright (c) 2021 X-Squared on Demand
<br />
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.
<br />
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).
Expand Down
245 changes: 211 additions & 34 deletions doc-assets/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,60 +12,237 @@ <h1><a href="./RecordTypes.html">Record Types Utilities</a></h1>
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.
</p>

<!--
<h2>Additional/Changed Header</h2> -->
<p>
Updated by David Schach, copyright (c) 2021 X-Squared on Demand

<br />
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.
<br />
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).
</p>


<h1>Record-Types</h1>
<p>
This is a project based on work by <a href="https://github.com/groundwired">Evan Callahan</a> (formerly of Groundwire, and now at Salesforce) who wrote
<a href="https://github.com/SalesforceFoundation/JenkinsTesting/blob/master/src/classes/RecordTypes.cls">this class</a> (Repo has been deleted. Sadface.) a long time ago to
reduce the number of describe calls required to work with Record Types.
</p>
<p>I&#39;ve updated the project (by pulling test code out of the main class - that&#39;s how old it was!) and have added some additional methods.</p>
<p>The included test class has 100% coverage, so pull this into your org and get cracking!</p>
<p>This is a project based on work by <a href="https://github.com/groundwired">Evan Callahan</a> (formerly of Groundwire, and now at Salesforce) who wrote <a href="https://github.com/SalesforceFoundation/JenkinsTesting/blob/master/src/classes/RecordTypes.cls">this class</a> (Repo has been deleted. Sadface.) a long time ago to reduce the number of describe calls required to work with Record Types.</p>
<p>I&#39;ve updated the project (by pulling test code out of the main class - that&#39;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!</p>
<p>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.</p>
<h2>Badges</h2>
<p>
<a href="https://www.gnu.org/licenses/gpl-3.0"><img src="https://img.shields.io/badge/License-GPLv3-blue.svg" alt="License: GPL v3" /></a>
<a href="https://codecov.io/gh/dschach/record-types"><img src="https://codecov.io/gh/dschach/record-types/branch/main/graph/badge.svg?token=RVhs6ab2Md" alt="codecov" /></a>
<a href="https://github.com/dschach/record-types/actions/workflows/ci.yml"><img src="https://github.com/dschach/record-types/actions/workflows/ci.yml/badge.svg" alt="CI" /></a>
<a href="https://img.shields.io/twitter/follow/dschach.svg?style=social"><img src="https://img.shields.io/twitter/follow/dschach.svg?style=social" alt="Twitter" /></a>
</p>
<p><a href="https://www.gnu.org/licenses/gpl-3.0"><img src="https://img.shields.io/badge/License-GPLv3-blue.svg" alt="License: GPL v3"></a>
<a href="https://codecov.io/gh/dschach/record-types"><img src="https://codecov.io/gh/dschach/record-types/branch/main/graph/badge.svg?token=RVhs6ab2Md" alt="codecov"></a>
<a href="https://github.com/dschach/record-types/actions/workflows/ci.yml"><img src="https://github.com/dschach/record-types/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
<a href="https://github.com/dschach/record-types/actions/workflows/pr.yml"><img src="https://github.com/dschach/record-types/actions/workflows/pr.yml/badge.svg" alt="Scratch Org"></a>
<a href="https://img.shields.io/twitter/follow/dschach.svg?style=social"><img src="https://img.shields.io/twitter/follow/dschach.svg?style=social" alt="Twitter"></a></p>
<h2>The Code</h2>
<p>The class and test class are found in this <a href="/force-app/main/default/classes/">folder</a>. Feel free to copy/paste directly into your org.</p>
<h2>Documentation</h2>
<p><a href="https://dschach.github.io/record-types/RecordTypes.html">ApexDox</a> (generated with <a href="https://github.com/no-stack-dub-sack/apexdox-vs-code">ApexDox</a>)</p>
<h2>Installation</h2>

<ul>
<li>Clone this repository and run <code>. scripts/orginit.sh</code> to set up a scratch org with the classes installed and a single Account Record Type.</li>
<li>To set up a scratch org without creating a Record Type, run <code>.scripts/orginit-norecordtypes.sh</code></li>
<li>Clone this repository and run <code>. scripts/orginit.sh</code> to set up a scratch org with the classes installed and a single Account Record Type.</li>
<li>To set up a scratch org without creating a Record Type, run <code>.scripts/orginit-norecordtypes.sh</code></li>
</ul>
<h2><a href="./changelog.html">Changelog</a></h2>
<ul>
<li>
<p>2023-08-18</p>
<ul>
<li>Add methods to get default RecordTypeId, handling situation where no RT is on the Profile but at least one is avaialble via Permission Set.</li>
<li>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.)</li>
</ul>
</li>
<li><p>2022-03-29 BREAKING CHANGE: Replaced &quot;DeveloperName&quot; with &quot;DevName&quot; in all method names. Update your code to refer to the new methods.</p></li>
<li>
<p>
2022-03-29 Add maps Id =&gt; Name and Id =&gt; DeveloperName for ease of use when wanting to refer to a record type by Id without including the object, since Id is globally
unique
</p>
</li>
<li><p>2022-01-19 Initial Release</p></li>
<li><p>2023-08-18</p>
<ul>
<li>Add methods to get default RecordTypeId, handling situation where no RT is on the Profile but at least one is avaialble via Permission Set.</li>
<li>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.)</li>
</ul>
</li>
<li><p>2022-03-29 BREAKING CHANGE: Replaced &quot;DeveloperName&quot; with &quot;DevName&quot; in all method names. Update your code to refer to the new methods.</p>
</li>
<li><p>2022-03-29 Add maps Id =&gt; Name and Id =&gt; DeveloperName for ease of use when wanting to refer to a record type by Id without including the object, since Id is globally unique</p>
</li>
<li><p>2022-01-19 Initial Release</p>
</li>
</ul>

<style>
.methodtable {
border-collapse: collapse;
width: 100%;
color: #333;
font-family: Arial, sans-serif;
font-size: 14px;
text-align: left;
border-radius: 10px;
overflow: hidden;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
margin: auto;
margin-top: 50px;
margin-bottom: 50px;
}
.methodtable th {
color: #000;
font-weight: bold;
padding: 10px;
text-transform: uppercase;
letter-spacing: 1px;
border-top: 1px solid #fff;
border-bottom: 1px solid #ccc;
}
.methodtable td {
padding: 10px;
border-bottom: 1px solid #ccc;
font-weight: bold;
}
</style>
<h1>Most Common Methods</h1>
<p>
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.
<br />
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.
</p>
<table class="methodtable">
<thead>
<tr>
<th><strong>Parameters / Output</strong></th>
<th>Id</th>
<th>Name</th>
<th>DeveloperName</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>objectName, recordTypeName</strong></td>
<td><a href="RecordTypes.html#RecordTypes.getRecordTypeIdFromName">getRecordTypeIdFromName</a></td>
<td></td>
<td></td>
</tr>
<tr>
<td><strong>objectName, recordTypeName</strong></td>
<td></td>
<td></td>
<td><a href="RecordTypes.html#RecordTypes.getRecordTypeIdFromName">getRecordTypeDevNameFromName</a></td>
</tr>
<tr>
<td><strong>objectName, recordTypeDevName</strong></td>
<td></td>
<td></td>
<td><a href="RecordTypes.html#RecordTypes.getRecordTypeIdFromName">getRecordTypeFromDevName</a></td>
</tr>
<tr>
<td><strong>objectName, recordTypeDevName</strong></td>
<td></td>
<td><a href="RecordTypes.html#RecordTypes.getRecordTypeIdFromName">getRecordTypeNameFromDevName</a></td>
<td></td>
</tr>
<tr>
<td><strong>objectName, recordTypeDevName</strong></td>
<td><a href="RecordTypes.html#RecordTypes.getRecordTypeIdFromName">getRecordTypeIdFromDevName</a></td>
<td></td>
<td></td>
</tr>
<tr>
<td><strong>objectName, recordTypeId</strong></td>
<td></td>
<td><a href="RecordTypes.html#RecordTypes.getRecordTypeIdFromName">getRecordTypeNameFromId</a></td>
<td></td>
</tr>
<tr>
<td><strong>objectName, recordTypeId</strong></td>
<td></td>
<td></td>
<td><a href="RecordTypes.html#RecordTypes.getRecordTypeIdFromName">getRecordTypeDevNameFromId</a></td>
</tr>
<tr>
<td><strong>recordTypeId</strong></td>
<td></td>
<td><a href="RecordTypes.html#RecordTypes.getRecordTypeIdFromName">getRecordTypeNameFromId</a></td>
<td></td>
</tr>
<tr>
<td><strong>recordTypeId</strong></td>
<td></td>
<td></td>
<td><a href="RecordTypes.html#RecordTypes.getRecordTypeIdFromName">getRecordTypeDevNameFromId</a></td>
</tr>
</tbody>
</table>

<h1>Less Common Methods</h1>
<p>
These methods are used less often but may be useful.
<br />
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.
</p>
<table class="methodtable">
<thead>
<tr>
<th><strong>Parameters / Output</strong></th>
<th>Schema.RecordTypeInfo</th>
<th>Map(String, Id)</th>
<th>SelectList</th>
<th>Set&lt;Id&gt;</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>objectName, recordTypeId</strong></td>
<td><a href="RecordTypes.html#RecordTypes.getRecordTypeIdFromName">getRecordTypeFromId</a></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td><strong>objectName, Set&lt;recordTypeDevName&gt;</strong></td>
<td></td>
<td></td>
<td></td>
<td><a href="RecordTypes.html#RecordTypes.getRecordTypeIdFromName">getRecordTypeIdSetFromDevNames</a></td>
</tr>
<tr>
<td><strong>objectName</strong></td>
<td></td>
<td><a href="RecordTypes.html#RecordTypes.getRecordTypeIdFromName">getRecordTypeDevNameIdMap</a></td>
<td></td>
<td></td>
</tr>
<tr>
<td><strong>objectName</strong></td>
<td></td>
<td><a href="RecordTypes.html#RecordTypes.getRecordTypeIdFromName">getRecordTypeNameIdMap</a></td>
<td></td>
<td></td>
</tr>
<tr>
<td><strong>objectName</strong></td>
<td></td>
<td><a href="RecordTypes.html#RecordTypes.getRecordTypeIdFromName">getAvailableRecordTypeDevNameIdMap</a></td>
<td></td>
<td></td>
</tr>
<tr>
<td><strong>objectName</strong></td>
<td></td>
<td><a href="RecordTypes.html#RecordTypes.getRecordTypeIdFromName">getAvailableRecordTypeNameIdMap</a></td>
<td></td>
<td></td>
</tr>
<tr>
<td><strong>objectName</strong></td>
<td></td>
<td></td>
<td><a href="RecordTypes.html#RecordTypes.getRecordTypeIdFromName">getRecordTypesForSelectList</a></td>
<td></td>
</tr>
<tr>
<td><strong>objectName</strong></td>
<td></td>
<td></td>
<td><a href="RecordTypes.html#RecordTypes.getRecordTypeIdFromName">getAllRecordTypesForSelectList</a></td>
<td></td>
</tr>
<tr>
<td><strong>objectName</strong></td>
<td></td>
<td></td>
<td><a href="RecordTypes.html#RecordTypes.getRecordTypeIdFromName">getStringRecordTypesForSelectList</a></td>
<td></td>
</tr>
</tbody>
</table>
Loading

0 comments on commit 3487d30

Please sign in to comment.