Skip to main content

Posts

Showing posts from December, 2020

How to access Record Types in Apex: Apex Record Type Provider

I’ve had a pleasure to watch many Salesforce technical architects trying to find a perfect way, how to work with Record Types in Apex . One created class Global_Constants to store all Record Type Ids and DeveloperNames in static properties, the other queried RecordType table and put the result in the map. I was never impressed so I‘ve come up with Record Type Provider , that allows you to access RecordTypeId like this: RecordTypeProvider.[ObjectName].[RecordTypeName].Id . It’s not perfect, but it definitely has its pros. What doesn’t work First, I would like to stop by the usual solutions and explain, why they do not work (well). Querying the RecordType table is extremely fast – you get all the Record Type descriptions in few miliseconds, but on the other hand you lose what every Salesforce developer must treasure the most – SOQL query . You may think, that you have only limited amount of classes and this one tiny query will never mean anything, but over time logic in your o...

About author

My photo
Jan Binder
Experienced Salesforce Technical Architect and Team Lead with a proven track record of delivering successful enterprise projects for major global companies across diverse industries, including automotive, oil & gas, and construction.