Ultimate Guide to Mastering Salesforce
LWC and Apex
1. Lightning Web Components (LWC) Deep Dive
Core Concepts
● Component Lifecycle Hooks: Master constructor(), connectedCallback(),
renderedCallback(), and disconnectedCallback() for DOM manipulation
and resource cleanup.
● Decorators:
○ @api (public properties/methods), @track (reactive properties), @wire
(data streaming from Apex or Lightning Data Service).
● Reactivity: Use tracked properties, getters, and refreshApex() to manage
dynamic UI updates.
Component Communication
● Parent ↔ Child: Props down, events up (e.g., dispatchEvent with
CustomEvent).
● Sibling/Unrelated Components: Use Lightning Message Service (LMS) or
pub-sub patterns.
● Cross-Domain: Communicate with Aura/Visualforce via LMS or postMessage.
Data Handling
● Lightning Data Service (LDS): CRUD operations without Apex. Handle
caching, error states, and record updates.
● Wire Adapters: Reactive data fetching (@wire with Apex methods or
getRecord).
● Imperative Apex Calls: For non-reactive scenarios (e.g., button clicks).
Performance & Optimization
● Lazy Loading: Dynamic imports for heavy JS libraries (e.g.,
import('[Link]')).
● Conditional Rendering: Use if:true|false and lwc:dom="manual" to
minimize reflows.
● Shadow DOM: Encapsulate CSS/JS and avoid global style pollution.
Testing & Debugging
● Jest Unit Tests: Mock @wire, Apex, and LMS. Achieve 75%+ test coverage.
● Browser Tools: Use Salesforce Chrome DevTools for component inspection
and event tracking.
2. Apex Mastery
Bulkification & Optimization
● Trigger Frameworks: Implement single-trigger-per-object patterns with
handler classes (e.g., TriggerHandler).
● SOQL/SOSL Best Practices:
○ Avoid nested loops; use maps for lookups.
○ Write selective queries (indexed fields) and limit results with
LIMIT/OFFSET.
● Governor Limits: Mitigate CPU timeouts, heap issues, and DML limits with
batch processing.
Asynchronous Processing
● Queueable Apex: Chain jobs and handle complex async workflows.
● Batch Apex: Process 50k+ records with start, execute, finish methods.
● Scheduled Apex: Use [Link]() for time-based operations.
Security & Design Patterns
● CRUD/FLS Enforcement: Use WITH SECURITY_ENFORCED in SOQL and
[Link]().
● Patterns:
○ Factory: Dynamic object creation.
○ Repository: Abstract database operations for testability.
○ Strategy: Swap algorithms at runtime (e.g., payment gateways).
Integration & APIs
● REST/SOAP APIs: Design secure endpoints with OAuth 2.0 (JWT bearer flow)
and rate limiting.
● Callouts: Use HttpCalloutMock for testing and handle retries.
● Platform Events: Decouple systems with event-driven architectures.
Testing & Debugging
● Test-Driven Development (TDD): Use [Link]()/[Link]()
for governor limit resets.
● Exception Handling: Custom exceptions with throw and try-catch-finally.
3. Advanced Integration Topics
LWC + Apex Synergy
● Caching Strategies: Use Platform Cache to reduce Apex calls (session/org
caches).
● Error Handling: Gracefully handle Apex exceptions in LWC with try/catch and
toast messages.
Security & Deployment
● DevOps: Implement CI/CD with Salesforce DX, scratch orgs, and VS Code.
● Security Audits: Enforce CSP Trusted Sites and sanitize inputs to prevent
XSS.
Third-Party Integrations
● External JS Libraries: Load via CDN with
lightning/platformResourceLoader.
● Canvas Apps: Embed external apps securely using OAuth and signed
requests.
4. Real-World Scenarios & Interview Prep
Common Use Cases
● Dynamic Forms: Build UI that adapts to user roles or data changes (e.g.,
lightning-record-edit-form).
● Data Tables: Implement client-side sorting/pagination with
lightning-datatable.
● File Uploads: Use lightning-file-upload with Apex ContentVersion
handling.
Interview Questions to Expect
1. How do you bulkify a trigger that updates related records?
○ Answer: Use maps to aggregate data, avoid DML inside loops, leverage
@future for async updates.
2. Explain LWC reactivity vs. Aura.
○ Answer: LWC uses modern JS proxies for granular updates; Aura relies
on value providers.
3. Design a screen with 10+ components sharing data.
○ Answer: Use LMS for pub-sub or a centralized state management
pattern.
4. Optimize a SOQL query hitting CPU limits.
○ Answer: Add selective filters, use indexed fields, or switch to SOSL.
5. Pro Tips for Success
● Best Practices:
○ Use @AuraEnabled(cacheable=true) for cacheable Apex methods.
○ Avoid renderedCallback overuse—it’s triggered on every render.
● Resources:
○ Trailhead: Advanced Apex Specialist, LWC Superbadge.
○ Tools: Salesforce CLI, Workbench, Postman for API testing.