Architecture Decisions
Flow vs. Apex vs. MuleSoft — Decision Matrix
A practical guide for admins and architects to choose the right tool for automation. This decision tree covers common use cases with clear recommendations based on complexity, maintainability, and scalability.
Criteria
Flow
Apex
MuleSoft
Ease of Development
Maintainability
Performance
Governor Limit Handling
Cross-System Integration
Debugging & Troubleshooting
Complex Transformations
Cost
Update a field on the same record after insert (e.g., set Status based on Amount)
Context: When an Opportunity is created, you need to automatically set the Status__c field to "High Priority" if Amount > $100,000, otherwise "Standard". This is simple field-level logic with no external systems involved.
FLOW
✓ Best
- Before-save flow runs before record commits — no extra DML
- Simple point-and-click decision logic
- Admin-friendly, no code deployment
- Built-in bulkification
APEX
~ Overkill
- Works perfectly in before trigger
- Requires developer + deployment
- Over-engineered for simple logic
- Test class overhead
MULESOFT
✗ Avoid
- Data must leave Salesforce for enrichment
- Extra round-trip latency (async)
- Adds infrastructure complexity
- No benefit for internal-only logic
Update parent Account when child Opportunity is closed (rollup summary alternative)
Context: When an Opportunity stage changes to "Closed Won", update the parent Account's "Last Win Date" and increment "Total Wins" counter. This is a simple parent-child update pattern.
FLOW
✓ Best
- After-save flow can update related records
- Visual logic easy to understand
- Handles bulk correctly with Get/Update Records
- Careful: don't query in loops
APEX
~ OK
- After-trigger handles this cleanly
- Better if complex aggregation logic
- Requires code for simple updates
- Flow is sufficient for this case
MULESOFT
✗ Avoid
- Unnecessary external orchestration
- Salesforce handles this natively
- Async delay not acceptable here
- No cross-system need
Complex validation with external credit check API before record creation
Context: Before creating an Account, call a third-party credit scoring API. If credit score < 600, prevent creation with error message. If 600-700, set to "Review Required". If > 700, auto-approve and create related Contract record. This involves external callouts, conditional logic, and multi-object DML.
FLOW
✗ Avoid
- Cannot do callouts in before-save flows
- Screen flow forces manual intervention
- Error handling limited in flows
- Complex branching becomes unmaintainable
APEX
✓ Best
- Full control over HTTP callout + retry logic
- Can use @future for async callout
- Rich error handling with try-catch
- Easily testable with mock callouts
MULESOFT
~ OK
- If API enrichment before SF insert is standard pattern
- Mule can validate, enrich, then upsert to SF
- Adds latency — not real-time validation
- Requires data to route through Mule first
Sync 50,000+ records daily from ERP system to Salesforce (Orders, Products, Inventory)
Context: Every night, a batch job pulls Orders, Products, and Inventory levels from SAP/NetSuite/Oracle ERP and needs to upsert them into Salesforce. Data transformation includes mapping ERP codes to Salesforce External IDs, currency conversion, and splitting single ERP records into multiple SF objects (Order + Line Items).
FLOW
✗ Avoid
- Flows cannot accept external data directly
- No batch processing for 50k+ records
- Governor limits hit quickly at scale
- Not designed for ETL workloads
APEX
~ OK
- Batch Apex can handle large volumes
- Invocable from external systems via REST API
- Transformation logic in Apex = tight coupling
- Batch Apex: 5 jobs queued max, slower
MULESOFT
✓ Best
- Bulk API 2.0 auto-chunks into 10k batches
- DataWeave for complex transformations
- Error handling: failed records → retry queue
- Decouples ERP from SF (no tight dependency)
When Order is placed in Salesforce, create shipment in warehouse system AND send confirmation email
Context: User clicks "Submit Order" button on a Lightning page. This needs to: (1) Create Order record in SF, (2) Call warehouse API to reserve inventory and create shipment, (3) Call email service to send confirmation, (4) Update Order with tracking number from warehouse response. All must happen in real-time.
FLOW
✗ Avoid
- HTTP callouts in flows are limited
- Cannot chain multiple callouts reliably
- Poor error recovery (retry, rollback)
- Mixing DML + callouts causes issues
APEX
~ OK
- @future(callout=true) for async callouts
- Platform Events for decoupled orchestration
- Complex to coordinate multi-step workflows
- All logic tightly coupled in SF
MULESOFT
✓ Best
- Built for orchestration workflows
- Saga pattern: rollback on any step failure
- Retry policies + circuit breakers
- SF publishes event → Mule orchestrates
Enrich Contact with company data from Clearbit/ZoomInfo before inserting into Salesforce
Context: Sales team imports leads from a CSV or web form. Before creating Contact records, you want to call Clearbit API to enrich with company name, industry, employee count, and LinkedIn URL. If enrichment fails, still create the Contact with partial data.
FLOW
✗ Avoid
- Before-save flows cannot do callouts
- After-save requires extra update DML
- Poor handling of API failures
- User waits for async enrichment
APEX
~ OK
- Platform Event → async enrichment in trigger
- Queueable Apex for chained callouts
- Still requires record insert before enrichment
- Not ideal for pre-insert enrichment
MULESOFT
✓ Best
- Data routes through Mule BEFORE SF insert
- Enrich → Transform → Upsert in one flow
- Graceful degradation on API failure
- Records arrive in SF fully enriched
Quick Decision Tree — When to Use What
Reference
┌─────────────────────────────────────────────────────────────────┐
│ START: What are you trying to automate? │
└─────────────────────────────────────────────────────────────────┘
│
┌─────────┴─────────┐
Does it involve │
external systems? │
│ │
┌───────┴───────┐ │
YES NO │
│ │ │
▼ ▼ │
┌───────────────┐ ┌────────────────┤
│ EXTERNAL? │ │ INTERNAL-ONLY? │
└───────────────┘ └────────────────┘
│ │
│ ├── Simple field update (same object)?
│ │ → FLOW (before-save)
│ │
│ ├── Cross-object update (parent/child)?
│ │ → FLOW (after-save) OR APEX if complex
│ │
│ ├── Complex calculations / validation?
│ │ → APEX
│ │
│ ├── Bulk processing (>10k records)?
│ → APEX Batch
│
├── Single API call (enrich/validate)?
│ │
│ ├── Real-time user action?
│ │ → APEX (with @future or Platform Event)
│ │
│ └── Async batch enrichment?
│ → MULESOFT (if data comes from outside)
│ → APEX Batch (if data already in SF)
│
├── Multi-step orchestration (warehouse + email + payment)?
│ → MULESOFT (built for workflows)
│
├── High-volume ETL (ERP → Salesforce)?
│ → MULESOFT with Bulk API 2.0
│
└── Pre-insert enrichment (data arrives enriched)?
→ MULESOFT (enrich before upsert)
╔══════════════════════════════════════════════════════════════╗
║ GENERAL RULES OF THUMB ║
╠══════════════════════════════════════════════════════════════╣
║ • Start with FLOW when possible (admin-friendly, fast) ║
║ • Escalate to APEX when: ║
║ - Complex logic, loops, or external callouts needed ║
║ - Governor limit control required ║
║ - Version control + automated testing critical ║
║ • Escalate to MULESOFT when: ║
║ - Multiple systems involved in one workflow ║
║ - High-volume data sync (>10k records) ║
║ - Pre-insert enrichment from external APIs ║
║ - Reusable integration assets across projects ║
╚══════════════════════════════════════════════════════════════╝