Record Type Ids in Salesforce

Record types in Salesforce play a large part in its declarative development. Their primacy in the platform make them particularly useful and important. Just like many other records, the record type id can be very useful. Unlike the record ids for standard and custom objects like contacts and accounts, however, record type ids can be more difficult to obtain.

IDs in the URl

You CAN indeed obtain record type ids like other ids within a Salesforce URL. For a standard object, navigate to Setup>Customise>[object]>Record Types. For custom objects, navigate to Setup>Create>Object>[object]. Click on any record type and then look at the URL. It might be easier to copy and paste the URL into a text editor.

https://eu5.salesforce.com/setup/ui/recordtypefields.jsp?id=01224000000FA6y&type=Account&setupid=AccountRecords

Within the URL there will be a question mark. This question mark signals the beginning of the URL parameters. The record type’s id is listed as the ‘id’ parameter.

Beyond serving as a way to differentiate page layouts based on user profiles and a way to present different picklist values to an end user, record type ids are very useful when performing SOQL queries.

[How to get record type ids via SOQL]

ids obtained via Soql

For those of you with limited experience using SOQL, the act of creating a SOQL query can be intimidating. Using SOQL to obtain a record type id, however, is relatively simple and hopefully this will give you the confidence to explore other ways in which querying data like this can be useful.

There are many ways to invoke a SOQL query in the Salesforce universe. I’m going to use the Developer Console in this instance as it’s available in all Salesforce editions and is quite simple. Open up the Developer Console by clicking on the down arrow next to your name and selecting ‘Developer Console’ from the menu. It’s possible that if the Salesforce org you work in is several years old that you may have to click on the down arrow next to ‘Setup’ instead. Either way, open up the Developer Console.

Within the Developer Console itself, select the ‘Query Editor’ tab and in the blank space below, type in the following query and hit ‘Execute’

SELECT Name, Id, sObjectType FROM RecordType

A list of ALL record types for ALL objects in your org should appear. As you can see, record type itself is just one big table in the database. Do you want to only list those for Account? Or perhaps you know the exact name of the record type whose Id you need. I’ve included SOQL queries below that utilise the ‘WHERE’ clause and allow you to refine your search to exactly what you need.

SELECT Name, Id, sObjectType FROM RecordType WHERE sObjectType = 'Account'
SELECT Name, Id, sObjectType FROM RecordType WHERE Name = 'My Favourite Record Type'

Record types are a fundamental building block in the Salesforce environment and the use of their ids is becoming more and more essential in declarative development. I hope this gives you the tools you need to access those ids and create high quality applications on the Salesforce platform.

Leave a Reply

Your email address will not be published. Required fields are marked *