Apex with Flow & Automation
What Is Automation in Salesforce?
Short Description
Salesforce automation lets you run actions automatically when data changes—without (or with minimal) manual effort.
Simple Explanation
Automation is like setting rules on your phone:
when something happens → Salesforce reacts.
Gist (Quick Revision)
Automation removes manual work and keeps processes consistent.
Invocable Apex
What Is Invocable Apex?
Invocable Apex allows Flows to call Apex methods when logic becomes too complex for clicks.
Simple Explanation
Flow handles the process, Apex handles the heavy logic.
Real-Life Example
A Flow collects user input, then calls Apex to:
-
Calculate discounts
-
Apply complex validations
-
Integrate with an external system
Basic Invocable Apex Example
public class DiscountCalculator {
@InvocableMethod(label='Calculate Discount')
public static List<Decimal> calculate(List<Decimal> amounts) {
List<Decimal> discounts = new List<Decimal>();
for (Decimal amt : amounts) {
discounts.add(amt * 0.10);
}
return discounts;
}
}
This method can now be used directly inside Flow.
When to Use Invocable Apex
-
Complex calculations
-
Reusable logic
-
Performance-critical steps
Gist (Quick Revision)
Invocable Apex connects clicks (Flow) with code (Apex).
Flow vs Apex vs Workflow
Workflow Rules (Legacy)
-
Simple field updates
-
Email alerts
-
Being phased out
Workflow = old & limited
Flow (Low-Code Powerhouse)
-
Visual builder
-
User interaction
-
Handles most automation needs
Flow = default choice today
Apex (Code-Based Control)
-
Complex logic
-
Bulk processing
-
Integrations
-
Performance optimization
Apex = power & flexibility
Easy Comparison Table
| Tool | Best For |
|---|---|
| Workflow | Simple legacy rules |
| Flow | Most business automation |
| Apex | Complex, bulk, or integration logic |
Real-Life Example
-
Update a field → Flow
-
Validate 200 records → Apex
-
Call an external API → Apex
-
Guide user through steps → Flow
Gist (Quick Revision)
Use Flow first, Apex when Flow is not enough.
Best-Use Decision Patterns (Very Important)
Decision Pattern 1: Can Flow Do It?
-
Yes → Use Flow
-
No → Use Apex
Decision Pattern 2: Does It Need Code?
Use Apex when:
-
Complex loops or calculations
-
Large data volumes
-
External integrations
-
Reusable logic across systems
Decision Pattern 3: Hybrid Approach (Best Practice)
Combine both:
-
Flow → Orchestration & UI
-
Apex → Business logic
Visual Memory Tip
Flow = Brain
Apex = Muscles
Interview Tip (Career Coach Insight)
Strong interview answer:
“I use Flow for orchestration and Invocable Apex for complex logic.”
This shows modern Salesforce best practices.
Gist (Quick Revision)
Choose Flow for simplicity, Apex for power, and combine both for best results.
