Close Menu

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    Agentforce Campaign Experience: How to Create Multi-Channel Campaigns Using Conversation

    May 14, 2026

    How to Get the Most Out of Agentforce World Tour and Dreamforce in 2026

    May 11, 2026

    Dreamforce 2026 Complete Guide: Key Dates, Sessions, & What to Expect

    May 8, 2026
    Facebook X (Twitter) Instagram
    Facebook Instagram LinkedIn WhatsApp Telegram
    Salesforce TrailSalesforce Trail
    • Home
    • Insights & Trends
    • Salesforce News
    • Specialized Career Content
      • Salesforce
      • Administrator
      • Salesforce AI
      • Developer
      • Consultant
      • Architect
      • Designer
    • About Us
    • Contact Us
    Salesforce TrailSalesforce Trail
    Home - Developer - Build a Dynamic, Reusable Lightning Datatable in Salesforce LWC (With Metadata-Driven Columns, Search & Pagination)
    Developer

    Build a Dynamic, Reusable Lightning Datatable in Salesforce LWC (With Metadata-Driven Columns, Search & Pagination)

    Kiran Sreeram PrathiBy Kiran Sreeram PrathiNovember 25, 2025Updated:November 25, 20257 Mins Read
    Facebook LinkedIn Telegram WhatsApp
    Build a Dynamic, Reusable Lightning Datatable in Salesforce LWC
    Share
    Facebook LinkedIn Email Telegram WhatsApp Copy Link Twitter

    Have you ever built multiple lightning-datatable components — one for Accounts, one for Contacts, and yet another for custom objects — each time duplicating the same logic?

    What if you could build one reusable lightning datatable that can display any object’s data dynamically, with automatic column generation, search, pagination, and toast messages?

    In this blog, we’ll build a fully dynamic, metadata-driven Data Table in LWC that works for any Salesforce Standard or Custom Object — without changing a single line of front-end code.

    Key Features:

    • Works for any SObject (Standard or Custom)
    • Dynamic SOQL and field validation in Apex
    • Auto-generated columns with correct labels and field types
    • Client-side search
    • Client-side pagination (10 records per page)
    • Toast notifications for success, errors, and no records
    • Graceful “No records found” message

    Picture1 1

    Architecture Overview:

    • Apex Controller: Accepts a dynamic request (object name, fields, conditions, limit) and returns metadata + records.
    • Parent LWC: Calls Apex, handles success/error toasts.
    • Child LWC: Displays data dynamically with search and pagination.

    Step 1: Apex Controller – DynamicDataTableController.cls

    We’ll create a single, flexible Apex class that accepts any object, any fields, and returns both the data and column metadata.

    Step 2: Parent LWC – UniversalDataWrapper

    This LWC sends the JSON request to Apex and handles toast notifications.
    universalDataWrapper.js

    universalDataWrapper.html

    universalDataWrapper.xml

    Step 3: Child LWC – Reusable Data Table

    reusableDatatable.js

    reusableDatatable.html

    reusableDatatable.xml

    How It Works:

    1. Parent LWC sends a JSON request → Apex
    2. Apex Controller dynamically validates fields, constructs SOQL, enforces FLS, and returns data + metadata
    3. Child LWC:
    • Auto-builds columns using metadata
    • Displays 10 records per page
    • Filters results instantly on search
    • Shows “No records found” when applicable

    UI Preview:

    Dynamic Reusable Data Table

    Example JSON Inputs:

    Final Output:

    • Works for any object
    • Auto column generation
    • Search & pagination
    • Success, info, and error toasts
    • Graceful empty state

    Next-Level Enhancements:

    • Add server-side pagination using OFFSET
    • Add sorting via onsort in <lightning-datatable>
    • Add export to CSV for filtered data
    • Add UI controls to select objects and Fields dynamically

    🔍 More by Author: Salesforce MVP Architecture: A Beginner’s Guide to Building Clean, Scalable Lightning Web Components 

    Salesforce Trail

    Conclusion:

    With this approach, you’ve built a universal, reusable LWC data table that’s fully metadata-driven, dynamic, secure, and user-friendly.
    No more duplicating components for each object — this one solution can power any list view, admin dashboard, or configuration UI.

    • This design pattern can easily evolve into a managed utility component or developer productivity accelerator inside your Salesforce org.

    Repo Link: https://github.com/kiransreeramprathi/salesforce-dynamic-datatable-lwc

    Certified_Agentforce-Specialist
    Salesforce Administrator
    Business Analyst New
    Sales-Cloud-Consultant
    Salesforce Platform-Developer-1

    Most Reads:

    • Salesforce Marketing Cloud to Agentforce: The Future of Marketing Automation
    • How to Create a WhatsApp Business Channel and Configure It in Meta Business Suite
    • How Salesforce Transformed My Career and Helped Me Build a Future in Tech
    • 5 Agentic Lessons Learned from the Rise of the Agentic Enterprise Era
    • Dreamforce 2025 Main Keynote Top Announcements You Can’t Miss
    • Your First 90 Days as a Salesforce Admin: A Step-by-Step Checklist

    Resources

    • [Salesforce Developer]- (Join Now)
    • [Salesforce Success Community] (https://success.salesforce.com/)

    For more insights, trends, and news related to Salesforce, stay tuned with Salesforce Trail

    Kiran Sreeram Prathi
    Kiran Sreeram Prathi
    Sr. Salesforce Developer – kiransreeram8@live.com

    I’m Kiran Sreeram Prathi, a Salesforce Developer dedicated to building scalable, intelligent, and user-focused CRM solutions. Over the past five years, I’ve delivered Salesforce implementations across healthcare, finance, and service industries—focusing on both technical precision and user experience. My expertise spans Lightning Web Components (LWC), Apex, OmniStudio, and Experience Cloud, along with CI/CD automation using GitHub Actions and integrations with platforms such as DocuSign, Conga, and Zpaper. I take pride in transforming complex workflows into seamless digital journeys and implementing clean DevOps strategies that reduce downtime and accelerate delivery. Recognized by organizations like Novartis, WILCO, and Deloitte, I enjoy solving problems that make Salesforce work smarter and scale better. I’m always open to connecting with professionals who are passionate about process transformation, architecture design, and continuous innovation in the Salesforce ecosystem.

      This author does not have any more posts.
    Apex Programming Dynamic Datatable Dynamic SOQL Lightning Datatable Lightning Web Components Metadata-Driven Components Reusable Lightning Datatable salesforce Salesforce AI Salesforce best practices Salesforce Development Salesforce LWC
    Share. Facebook LinkedIn Email Telegram WhatsApp Copy Link

    Related Posts

    Agentforce Campaign Experience: How to Create Multi-Channel Campaigns Using Conversation

    May 14, 2026

    Dreamforce 2026 Complete Guide: Key Dates, Sessions, & What to Expect

    May 8, 2026

    Slack as the Front Door to the Agentic Enterprise: Everything Salesforce Announced at TDX 2026

    May 6, 2026
    Add A Comment
    Leave A Reply Cancel Reply

    Advertise with Salesforce Trail
    Connect with Salesforce Trail Community
    Latest Post

    Salesforce Consultant Career Path: From Junior Consultant to Practice Lead

    March 25, 2026

    How to Hire Salesforce Consultants: Practical Tips Every Business Should Know

    February 19, 2026

    6 Proven Principles to Drive Faster Salesforce CRM Adoption

    November 3, 2025

    Driving Revenue Efficiency with Sales Cloud in Product Companies

    October 30, 2025
    Top Review
    Designer

    Customizing Salesforce: Tailor the CRM to Fit Your Business Needs

    By adminAugust 6, 20240

    Salesforce is an adaptable, powerful customer relationship management (CRM) software that businesses can customize, and…

    Sales Professional

    Unlock 10 Powerful Sales Pitches to Boost Your Revenue by 30X

    By Mayank SahuJuly 4, 20240

    Sales is a very competitive arena, and it is followed by one must have a…

    Salesforce Trail
    Facebook X (Twitter) Instagram LinkedIn WhatsApp Telegram
    • Home
    • About Us
    • Write For Us
    • Privacy Policy
    • Advertise With Us
    • Contact Us
    © 2026 SalesforceTrail.com All Right Reserved by SalesforceTrail

    Type above and press Enter to search. Press Esc to cancel.