Silly Dev Trick: Record Type Id without SOQL

Not rocket science but as usual there are a lot of bad posts on this so:

Schema.RecordTypeInfo rt = SObjectType.Opportunity.getRecordTypeInfosByDeveloperName().get('Developer_Name');
system.debug('Record Type ID: ' + rt.RecordTypeId); 

or super simplified: SObjectType.Opportunity.getRecordTypeInfosByDeveloperName().get('Developer_Name').RecordTypeId

Switch Opportunity for whatever object and tralala.

Leave a Reply

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