Advanced Apex Anti-Patterns - The Invisible Performance Killers
Advanced Apex Anti-Patterns The Invisible Performance Killers Three tricky architectural traps that silently drain CPU limits and crash multi-tenant transactions. Trap 1: The `SObjectType.getRecordTypeInfosByDeveloperName()` Loop Bleed We are taught to avoid hardcoding IDs by using Schema Describe methods. It looks clean, declarative, and completely safe. But what happens when you place describe calls inside a business logic loop? ❌ The Flawed Anti-Pattern: for (Account acc : trigger.new) { // Hidden Danger: Re-instantiating schema maps 200+ times per batch execution context Id corporateId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName() .get('Corporate_Account').getRecordTypeId(); if (acc.RecordTypeId == corporateId) { /* Process */ } } Why it's a Trap: While Sales...