20 Best Practices and Tips for LWC and Apex – TDX Bengaluru Recap : [email protected] (Kapil)
by: [email protected] (Kapil)
blow post content copied from Salesforce Bolt
click here to view original post
**Summary of the Session on Optimizing Salesforce Development** During the recent TDX Bengaluru event, I presented on a vital topic for Salesforce developers: optimizing our development practices. My session, titled “20 Minutes – 20 Best Practices and Tips for LWC and Apex,” provided a quick overview of essential strategies to enhance code quality, maintainability, and performance, suitable for both new and experienced developers. ### Key Takeaways: #### **Lightning Web Components (LWC) Best Practices:** 1. **Use Base Components:** Leverage Salesforce's optimized base components. 2. **Avoid Over-Modularization:** Only modularize when it adds value; too much can complicate your code. 3. **Build Reusable Components:** Design components for reusability based on logical functions. 4. **Follow Kebab-Case Naming:** Use kebab-case for component names (e.g., my-first-component). 5. **Render Multiple Templates:** Use conditional rendering for clarity across different UIs. 6. **Standardized Error Handling:** Implement reusable error panels and propagate errors appropriately. 7. **Use Lightning Data Service (LDS):** Prefer LDS for CRUD operations to respect security rules. 8. **Implement Lazy Loading:** Load components/data only when necessary to enhance performance. 9. **Communicate via Events:** Use appropriate communication patterns (child-to-parent, parent-to-child, or pub-sub). 10. **Be Careful with Case Sensitivity:** Remember that property names and variable references are case-sensitive. #### **Apex Best Practices:** 1. **Handle Batch Apex Responsibly:** Monitor existing batches to avoid conflicts. 2. **Control Trigger Recursion:** Use static variables wisely to manage execution flow. 3. **Bulkify Everything:** Ensure your code handles multiple records efficiently. 4. **Avoid DML and SOQL Inside Loops:** Keep these operations outside of loops to prevent governor limits issues. 5. **Use Limits Methods:** Utilize Salesforce's Limits class for staying within governor limits. 6. **Use Database Class Methods for DML:** These provide better control and error handling. 7. **Adopt an Error Logging Framework:** Centralize error logging for better issue management. 8. **Leverage Custom Settings & Metadata:** Store configuration data externally instead of hardcoding. 9. **Write Quality Test Classes:** Test for various scenarios including bulk records and restricted users. 10. **Use Return Early Pattern:** Enhance readability and efficiency by returning from methods as soon as possible. ### Additional Resources: For those who missed the session or wish to review the detailed content, the full session notes and presentation slides are available on GitHub: [TDX Bengaluru Session Notes](#). ### Closing Remarks: Thank you to everyone who participated! Your engagement and questions made the session unforgettable. Let's keep sharing knowledge and growing together in the Salesforce ecosystem! ### Hashtags for SEO: #TDXBengaluru #Salesforce #LWC #Apex #SalesforceDevelopers #TrailblazerCommunity #KapilBatra #DeveloperBestPractices #CodingTips #SoftwareDevelopment #TechCommunity Feel free to leave comments or share your thoughts! Happy Coding!
Earlier this month at TDX Bengaluru, I had the opportunity to speak on a topic close to every Salesforce developer’s heart — optimizing the way we build on the platform. My session, titled “20 Minutes – 20 Best Practices and Tips for LWC and Apex”, was a power-packed walkthrough of essential tips that can help both beginners and experienced developers improve code quality, maintainability, and performance.
In case you missed it or want to revisit the key points, here’s a quick summary of the takeaways.
⚡ Lightning Web Components (LWC) – 10 Best Practices
-
Use Base Components
Use Salesforce-provided base components whenever possible—they're optimized, tested, and customizable. -
Avoid Over-Modularization
Modularization is good, but too much can increase complexity. Always evaluate if breaking down is truly adding value. -
Build Reusable Components
Design your components with reusability in mind. Divide based on logical functionality. -
Follow Kebab-Case Naming
Naming conventions matter. LWC component names should followkebab-case
(e.g.,my-first-component
). -
Render Multiple Templates
Use conditional rendering to switch between templates and maintain code clarity for different UIs. -
Standardized Error Handling
Use reusable error panel components and propagate errors to parent components where applicable. -
Use Lightning Data Service (LDS)
Avoid Apex where possible—use LDS for basic CRUD operations, ensuring field-level security and sharing rules are respected. -
Implement Lazy Loading
Load components or data only when needed to improve performance. -
Communicate via Events
Understand and implement the right pattern—child-to-parent, parent-to-child, or pub-sub—for effective component communication. -
Be Careful with Case Sensitivity
Property names, object fields, and variable references in LWC are case-sensitive. Double-check your references!
💡 Apex – 10 Best Practices
-
Handle Batch Apex Responsibly
Don’t fire new batches if existing ones are running. Monitor usingAsyncApexJob
. -
Control Trigger Recursion
Use static variables wisely and reset them post execution. Pay attention totrigger.old
vs.trigger.new
. -
Bulkify Everything
Always write code that can handle multiple records at once. -
Avoid DML and SOQL Inside Loops
Move DML and SOQL operations outside of loops to avoid hitting governor limits. -
Use
Limits
Methods
Use Salesforce'sLimits
class to stay under governor limits and diagnose issues. -
Use
Database
Class Methods for DML
These offer better control and error handling options compared to simple DML statements. -
Adopt an Error Logging Framework
Implement a centralized error logging strategy to capture and analyze runtime issues effectively. -
Leverage Custom Settings & Metadata
Store config data in Custom Settings or Metadata instead of hardcoding values in Apex. -
Write Quality Test Classes
Test for bulk records, edge cases, restricted users, and avoid usingseeAllData=true
. -
Use Return Early Pattern
Improve method readability and reduce CPU time by returning as soon as your logic is complete.
📎 Get the Full Session Notes
I've made my complete session deck and notes public. You can find them here:
👉 GitHub: TDX Bengaluru Session Notes
🙏 Thank You!
A huge thank you to everyone who attended and packed the room! The questions, energy, and discussions truly made this session memorable. Let’s continue to share and grow together in this amazing ecosystem.
#TDXBengaluru #Salesforce #LWC #Apex #SalesforceDevelopers #TrailblazerCommunity #KapilBatra #DeveloperBestPractices
Checkout Complete Video Below
May 17, 2025 at 07:24PM
Click here for more details...
=============================
The original post is available in Salesforce Bolt by [email protected] (Kapil)
this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.
============================

Post a Comment