Record Types, Page Layouts & Schema
📖 Concept
Record Types allow you to offer different business processes, picklist values, and page layouts for the same object. They're a critical tool for building enterprise-grade solutions that serve multiple business units.
Record Types — when and why:
- Different divisions sell different products using the same Opportunity object
- Support teams handle different case categories with different fields
- Multiple countries have different compliance fields on the Account object
How Record Types work:
- Each record type maps to a Page Layout (which fields the user sees)
- Each record type can have different picklist values (e.g., different Status options)
- Record types are assigned to Profiles — users only see record types assigned to their profile
- Record types create different record creation flows (different fields presented)
- Records store their record type in the
RecordTypeIdfield
Page Layouts: Define the arrangement of fields, related lists, buttons, and components on a record page. Key capabilities:
- Control field visibility and read-only status
- Arrange fields in sections (1 or 2 columns)
- Add related lists (child records)
- Add custom buttons and links
- Include Visualforce pages or Lightning components
- Important: Page layouts control field visibility in the UI, NOT field-level security. FLS is separate.
Lightning Record Pages: Modern alternative to Page Layouts using Lightning App Builder:
- Drag-and-drop component placement
- Device-specific layouts (desktop, tablet, phone)
- Dynamic visibility rules (show components conditionally)
- Support for custom Lightning Web Components
- Can override standard page layouts
Schema Builder: Visual tool for designing data models:
- Drag-and-drop object and field creation
- Visual relationship mapping
- Real-time schema visualization
- Useful for documentation and planning
Enterprise considerations:
- Plan record types during data modeling, not as an afterthought
- Record type changes in production require careful migration (existing records)
- Page layout changes are metadata — deploy via change sets or SFDX
- Lightning Record Pages offer more flexibility than classic page layouts
- Consider record type impacts on reporting and dashboards
💻 Code Example
1// Working with Record Types in Apex23public class RecordTypeUtils {45 // 1. Get Record Type Id by Developer Name (best practice)6 public static Id getRecordTypeId(String objectName, String devName) {7 // Use Schema.SObjectType for reliable, cache-friendly access8 return Schema.getGlobalDescribe()9 .get(objectName)10 .getDescribe()11 .getRecordTypeInfosByDeveloperName()12 .get(devName)13 .getRecordTypeId();14 }1516 // 2. Create records with specific Record Types17 public static void createCases() {18 Id supportRT = getRecordTypeId('Case', 'Support_Case');19 Id bugRT = getRecordTypeId('Case', 'Bug_Report');2021 List<Case> cases = new List<Case>{22 new Case(23 Subject = 'Login Issue',24 RecordTypeId = supportRT,25 Priority = 'Medium',26 Status = 'New'27 ),28 new Case(29 Subject = 'Button not working',30 RecordTypeId = bugRT,31 Priority = 'High',32 Status = 'Open' // Different picklist for bug reports33 )34 };35 insert cases;36 }3738 // 3. Query and filter by Record Type39 public static List<Case> getCasesByType(String recordTypeName) {40 return [41 SELECT Id, Subject, Status, Priority, RecordType.Name42 FROM Case43 WHERE RecordType.DeveloperName = :recordTypeName44 AND Status != 'Closed'45 ORDER BY CreatedDate DESC46 ];47 }4849 // 4. Get available Record Types for current user50 public static List<Schema.RecordTypeInfo> getAvailableRecordTypes(51 String objectName52 ) {53 List<Schema.RecordTypeInfo> available = new List<Schema.RecordTypeInfo>();54 Map<String, Schema.RecordTypeInfo> rtMap =55 Schema.getGlobalDescribe()56 .get(objectName)57 .getDescribe()58 .getRecordTypeInfosByDeveloperName();5960 for (Schema.RecordTypeInfo rti : rtMap.values()) {61 if (rti.isAvailable() && !rti.isMaster()) {62 available.add(rti);63 }64 }65 return available;66 }6768 // 5. Dynamically assign Record Type based on criteria69 public static void assignRecordTypes(List<Case> cases) {70 Id supportRT = getRecordTypeId('Case', 'Support_Case');71 Id bugRT = getRecordTypeId('Case', 'Bug_Report');72 Id featureRT = getRecordTypeId('Case', 'Feature_Request');7374 for (Case c : cases) {75 if (c.Type == 'Bug') {76 c.RecordTypeId = bugRT;77 } else if (c.Type == 'Feature Request') {78 c.RecordTypeId = featureRT;79 } else {80 c.RecordTypeId = supportRT;81 }82 }83 }8485 // 6. Page Layout assignment query86 // (useful for understanding which layout a user sees)87 public static void checkLayoutAssignment() {88 // In Apex, you can't directly query page layout assignments89 // But you can use the Metadata API or Tooling API90 // Instead, use Record Type + Profile combination logic9192 // Determine what record types the running user can access93 Schema.DescribeSObjectResult caseDescribe = Case.SObjectType.getDescribe();94 Map<Id, Schema.RecordTypeInfo> rtById = caseDescribe.getRecordTypeInfosById();9596 for (Id rtId : rtById.keySet()) {97 Schema.RecordTypeInfo info = rtById.get(rtId);98 System.debug(info.getName() + ' — Available: ' + info.isAvailable() +99 ', Default: ' + info.isDefaultRecordTypeMapping());100 }101 }102}
🏋️ Practice Exercise
Record Type & Layout Exercises:
- Create 3 Record Types for the Case object: Support, Bug, Feature Request — each with different picklist values
- Create different Page Layouts for each Record Type with different field arrangements
- Build a Lightning Record Page with dynamic visibility (show components based on record type)
- Write Apex that creates records with specific Record Types using Developer Name (not hard-coded IDs)
- Write a SOQL query that groups cases by RecordType.Name and counts them
- Design a migration script that changes Record Types for 50,000 existing records
- Create a formula field that displays different text based on the Record Type
- Test what happens when a user tries to create a record with a Record Type not assigned to their Profile
- Build a complete Lightning page with custom LWC components that change based on Record Type
- Document all Record Types in your org and their Page Layout assignments
⚠️ Common Mistakes
Hard-coding Record Type IDs — IDs differ between sandbox and production. Always use DeveloperName to look up IDs at runtime
Confusing Page Layout field visibility with Field-Level Security — Page Layouts only affect UI display; FLS controls actual read/write access to the field at the API level
Creating too many Record Types — each one requires its own Page Layout, picklist value set, and testing. Start with 2-3 max per object
Not considering Record Type impact on data migration — when importing data, you must specify RecordTypeId or the default is used, which may not be correct
Forgetting that Record Types are assigned to Profiles — if you add a new Record Type, users won't see it until you assign it to their Profile
💼 Interview Questions
🎤 Mock Interview
Mock interview is powered by AI for Record Types, Page Layouts & Schema. Login to unlock this feature.