Monthly Archives: June 2014

Apex Tip: How to get a RecordType Id by Name without SOQL

The usual way to get a recordTypeId in Apex is to make a query like this:

Instead of that try this line:

Just replace Account and ‘Person Account’ by your Object and Record Type Name
I’ve been notice that “Person Account” is the label description and not the developer name of the Record Type. Having said that if you work in a multi-lang org, You’ll need to make a Query.
The most efficient way to make that kind of query is to cache the result in a static variable. Like this:


Happy coding

About Martin Borthiry

I’m a fully trained and qualified software engineer with more than 15 years of varied experience, specialized in frontend performance, web developing , cloud computing, salesforce, as well as CRM functionalties and Social Networks. Specialties: Platform & Web Performance Optimization. Developer and Administrator Certified. Senior Frontend, Javascript and HTML5. Heavy Ajax WebApps Mobile WebApps – Phonegap Webapps Developer (Php/Django/Python) Team Work & Managment Now leading a Salesforce applications company