Class Folder Organization Patterns
Introduction
Why Folder Organization Matters
The Problem with Flat Structure
// ❌ Default Salesforce structure with 200+ files
classes/
├── AccountService.cls
├── AccountServiceImpl.cls
├── AccountServiceTest.cls
├── AccountSelector.cls
├── AccountSelectorTest.cls
├── AccountDomain.cls
├── AccountDomainTest.cls
├── AccountTriggerHandler.cls
├── AccountFactory.cls
├── IAccountService.cls
├── IAccountSelector.cls
├── OrderService.cls
├── OrderServiceImpl.cls
├── OrderServiceTest.cls
... (185 more files)Folder Organization Patterns
1. Layer-Based Organization (fflib Pattern)
2. Test Organization Pattern
3. Sub-Package Organization
4. Interface Segregation Pattern
Package-Specific Application Classes
The Multi-Application Pattern
Why Multiple Selectors for Same Object?
Package Suffix Convention
Selector Factory Pattern
Using Package-Specific Components
Naming Conventions
Folder Names
Class Names
File Placement Rules
Benefits of Folder Organization
1. Improved Developer Experience
2. Better Code Quality
3. Team Scalability
4. Maintenance Benefits
Anti-Patterns to Avoid
1. Over-Nesting
2. Inconsistent Organization
3. Breaking Salesforce Conventions
Migration Strategy
Phase 1: Plan Structure
Phase 2: Gradual Migration
Phase 3: Update References
Production Implementation Results
Conclusion
Last updated
Was this helpful?