Introduction
As Salesforce implementations evolve from a single CRM to a connected enterprise platform, architectural decisions become far more important than individual code snippets.
Whether you’re building on Sales Cloud, Service Cloud, Experience Cloud, Data Cloud, or integrating with external systems, applying proven design patterns leads to solutions that are:
- Scalable
- Maintainable
- Reusable
- Testable
- Easier to extend
Great Salesforce Architects don’t just know Apex or Flows, they know which architectural pattern to apply for the right problem.
1️⃣ Service Layer Pattern
A Salesforce solution can have multiple entry points:
- Lightning Web Components (LWC)
- Aura Components
- Screen Flows
- Record-Triggered Flows
- Apex Triggers
- REST APIs
- Batch Apex
- Queueable Apex
- Scheduled Apex
Instead of implementing business logic in each entry point, centralize it in a Service Layer.
Instead of
LWC
Flow
Trigger
REST API
Each contains its own business logic
Use
LWC
Flow
Trigger
REST API
│
▼
Service Layer
│
▼
Domain Logic
│
▼
Selector Layer
│
▼
Salesforce Data Model
Benefits
✅ Single source of business logic
✅ Consistent behavior across all channels
✅ Easier testing
✅ Reduced duplication
2️⃣ Selector Pattern
Avoid writing SOQL queries throughout your Apex classes.
Instead, centralize all queries inside dedicated Selector classes.
Example:
AccountSelector.getActiveCustomers();
OpportunitySelector.getOpenOpportunities();
Benefits
- Centralized SOQL
- Easier query optimization
- Reduced duplicate queries
- Better maintainability
3️⃣ Domain Layer Pattern
Business rules should belong to the object they govern.
Instead of placing Account-related logic in triggers or controllers, encapsulate it within an Account Domain class.
Examples:
- Credit validation
- Account status rules
- Territory assignment
- Customer classification
Benefits
- Business rules remain close to the data model
- Improved readability
- Better separation of responsibilities
4️⃣ Unit of Work Pattern
Enterprise applications often perform multiple DML operations within a single transaction.
Instead of:
insert account;
update contact;
insert opportunity;
Use a Unit of Work to register changes and commit them together.
Benefits
- Fewer DML statements
- Better transaction management
- Cleaner rollback handling
- Improved governor limit utilization
5️⃣ Trigger Handler Pattern
Salesforce best practice is simple:
One Trigger per Object
Move all trigger logic into dedicated handler classes.
Account Trigger
│
▼
AccountTriggerHandler
│
├── beforeInsert()
├── beforeUpdate()
├── afterInsert()
└── afterDelete()
Benefits
- Thin triggers
- Easier debugging
- Better code organization
- Higher testability
6️⃣ Strategy Pattern
Avoid large IF-ELSE blocks based on business scenarios.
Example:
Lead Assignment
Lead Assignment Service
│
┌──────┼─────────┐
│ │ │
US EMEA APAC
Strategy Strategy Strategy
Each region implements its own assignment logic.
Salesforce Use Cases
- Lead Assignment
- Discount Calculations
- Tax Rules
- Pricing Engines
- Case Routing
Benefits
- Easily extensible
- Supports Open/Closed Principle
- Cleaner business logic
7️⃣ Factory Pattern
Instead of creating implementations directly:
new PaymentProcessor();
Use a Factory.
ProcessorFactory.getProcessor(type);
Salesforce Use Cases
- Payment Providers
- External Integrations
- Notification Services
- Document Generation
- File Storage Providers
Benefits
- Loose coupling
- Easier testing
- Flexible implementations
8️⃣ Event-Driven Architecture
Enterprise Salesforce implementations should minimize tight coupling.
Instead of:
Application A
│
calls
▼
Application B
Use Platform Events or Change Data Capture.
Salesforce
│
Platform Event
│
┌────┴─────────┐
│ │
ERP Marketing
│ │
Analytics Middleware
Salesforce Technologies
- Platform Events
- Change Data Capture (CDC)
- Event Relay
- Pub/Sub API
Benefits
- Loose coupling
- Asynchronous processing
- Better scalability
- Improved resilience
9️⃣ Anti-Corruption Layer (ACL)
Enterprise organizations often integrate Salesforce with legacy ERP, billing, or mainframe systems.
Instead of exposing Salesforce directly to legacy complexities, introduce an Anti-Corruption Layer.
Salesforce
│
▼
Integration Layer
(MuleSoft / API Gateway)
│
▼
Legacy Systems
Benefits
- Shields Salesforce from legacy data models
- Simplifies integrations
- Enables gradual modernization
- Reduces technical debt
🔟 Saga Pattern
A single business process may span multiple systems.
Example:
Customer Onboarding
Create Account
│
Create Contract
│
Provision Subscription
│
Create ERP Customer
│
Send Welcome Email
If one step fails, compensating actions undo previously completed steps.
Salesforce Use Cases
- Order Management
- Customer Onboarding
- Subscription Provisioning
- Multi-cloud Business Processes
Benefits
- Reliable distributed transactions
- Better fault tolerance
- Improved user experience
Adopting these patterns can significantly improve code consistency and maintainability across large Salesforce programs.
🎯 Key Takeaway
Writing Apex is a skill.
Designing solutions that remain maintainable, scalable, and adaptable over years of business change is the hallmark of a Salesforce Architect.
Enterprise design patterns provide a common language for development teams, reduce technical debt, and enable solutions that scale with the business—not just the current release.