Close Menu
SalesforceCodex
    Facebook X (Twitter) Instagram
    Trending
    • 10 Salesforce Chrome Extensions to Boost Your Productivity
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    • How to Suppress PMD Warnings in Salesforce Apex
    • Top 10 PMD Issues Salesforce Developers Should Focus on in Apex
    Facebook X (Twitter) Instagram
    SalesforceCodex
    Subscribe
    Saturday, June 21
    • Home
    • Architecture
    • Salesforce
      • News
      • Apex
      • Integration
      • Books Testimonial
    • Questions
    • Certification
      • How to Prepare for Salesforce Integration Architect Exam
      • Certification Coupons
    • Integration Posts
    • Downloads
    • About Us
      • Privacy Policy
    SalesforceCodex
    Home»Salesforce»Lightning»Adding table row dynamically in Lightning Web Component

    Adding table row dynamically in Lightning Web Component

    Dhanik Lal SahniBy Dhanik Lal SahniOctober 19, 2020Updated:June 11, 202323 Comments3 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    Adding table row dynamically in Lightning Web Component
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Recently I got requirement from one of our group member, to create dynamic configurable table creation for creating new record in Salesforce objects.

    Use Case:

    Create a configurable table for adding/deleting new rows in lightning data table. Types of fields will be configurable while adding new rows. On submit save record in multiple Salesforce objects.

    Solutions:

    There could be two below solutions for this use case

    1. Create a new dynamic lightning web component
    2. Use record-edit-form to create table

    This post will solve our use case using solution approach#1.

    1. Create a new dynamic lightning web component

    We can create one lightning web component which will handle table creation based on configured columns and it’s type. Before creating data table component, let us create field type components to configure these in data table. This field type component will help us in getting record values easily.

    Text Type component

    This component will create text field component for table. It will only rendered when cell type is text.

    Picklist type component

    This component will create picklist field component for table. Picklist values will show based on configuration properties.

    Picklist values will be populated based on object name and field name which is setup while configuring cell fields. getPicklist is called to get picklist values and it is rendered in lightning-combobox.

    AccountController.getPickList: This apex method will be used to get picklist values. See apex code from below attached apex class.

    Create table component

    Use above mentioned field components to create dynamic table. This table will add delete icon to delete row from table. On submit, record will be saved in multiple object using lightning data service.

    As there could be multiple records to save, each rows fields information is fetched using retrieveRecords methods and returned to caller. We have user css class to get each row fields information.

    Test Component:

    Now we are ready with component creation, let us test above created dynamic component. We have setup three columns, two are text fields and one is picklist. For picklist we have setup object name also. When submit button will be clicked, we need to fetch rows data and we can save using apex code.

    const columns=[
        { "label" : "Name", "apiName" : "Name" ,"fieldType":"text","objectName":"Account"}, 
        { "label" : "Phone", "apiName" : "Phone" ,"fieldType":"text","type":"phone","objectName":"Account"},
        { "label" : "Account Source", "apiName" : "AccountSource","fieldType":"picklist","objectName":"Account" }
    ];

    Apex Code:

    Test Page:

    Related Posts

    Dynamic Code Execution using Callable Interface

    Dynamic Record Page Creation using FieldSet

    Generic DataTable in Lightning Web Component

    apex dynamic datatable Lightning web component lightning-combobox lightning-datatable lwc picklist salesforce
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticlePublish Platform Events from ASP.NET
    Next Article Stop deselecting lightning-dual-listbox list
    Dhanik Lal Sahni
    • Website
    • Facebook
    • X (Twitter)

    With over 18 years of experience in web-based application development, I specialize in Salesforce technology and its ecosystem. My journey has equipped me with expertise in a diverse range of technologies including .NET, .NET Core, MS Dynamics CRM, Azure, Oracle, and SQL Server. I am dedicated to staying at the forefront of technological advancements and continuously researching new developments in the Salesforce realm. My focus remains on leveraging technology to create innovative solutions that drive business success.

    Related Posts

    By Dhanik Lal Sahni9 Mins Read

    10 Salesforce Chrome Extensions to Boost Your Productivity

    June 1, 2025
    By Dhanik Lal Sahni4 Mins Read

    How to Build a Generic Modal Window in Lightning Web Component

    May 26, 2025
    By Dhanik Lal Sahni6 Mins Read

    Top 10 Salesforce Flow Features of Salesforce Summer ’25

    May 11, 2025
    View 23 Comments

    23 Comments

    1. Vaibhav on June 1, 2021 10:09 pm

      Hi, I am getting this error..

      Unknown public property “objectApiName” of element . This is likely a typo on the corresponding attribute “object-api-name”.

      can u help

      Reply
      • Dhanik Lal Sahni on June 5, 2021 7:12 pm

        Hello Vaibhav, Please replace objectAPIName to objectApiName in dynamicTable.js part line#7.

        Thank You,
        Dhanik

        Reply
        • Rasmi on October 7, 2021 11:32 pm

          I have objectApiName in the datatable.js file. Still I get below error.
          Error during LWC component connect phase: [Unknown public property “objectApiName” of element . This is likely a typo on the corresponding attribute “object-api-name”.]

          Reply
          • Dhanik Lal Sahni on December 7, 2021 12:48 pm

            Hey Rashmi,

            Please check property name in js. If your property name is objectApiName then it will be added as object-api-name. If it is created as objectAPIName then use like object-a-p-i-name in template attribute. Character Casing impact usage in template. So please check and update code accordingly.

            Thank You,
            Dhanik

            Reply
    2. JONATHAN S FRIEDL on July 6, 2021 2:01 am

      Hello, is there a way to create the rows to support datatype textArea (long)(like this text box I’m currently writitng in) for individual rows, so that it displays more vertically? iI tried using class=”slds-scrollable_y”,.. I dont see it as supported in the documentation, also how would you make a field required?

      Thank you for this stuff all very great examples

      Reply
      • Dhanik Lal Sahni on July 8, 2021 5:12 pm

        Hello Jonathan,

        Similar to c-input-table-cell, you can create one component for text area like c-input-text-area and then you can use it. in InputTextArea component add text area component. Add template like below in that component

        <template>
        <lightning-textarea
        name=”myText”
        label=”Your Name”
        message-when-value-missing=”This field is required.”
        required>
        </lightning-textarea>
        </template><

        Thank You,
        Dhanik

        Reply
    3. Chris on July 6, 2021 10:59 pm

      I don’t understand how the columns are being created via the CSS component. Can you elaborate?

      Reply
      • Dhanik Lal Sahni on December 7, 2021 1:22 pm

        Hey Chris,

        It is done using dynamicTable.html code line # 17, 18.

        Thank You,
        Dhanik

        Reply
    4. Harini on August 31, 2021 2:54 am

      HI,
      The above helped a lot but I am also looking for lookup field to add the dynamic table. I am seeing some issues when I try to code it. Could you please provide some suggestions on how to tackle on javascript where you used field-type,field,record on individual components.

      Thank you in advance!

      Reply
      • Dhanik Lal Sahni on August 31, 2021 4:16 am

        Hey Harini,

        What issue are you getting, Please share that so that I can help you? Ping me in my telegram channel or linked-in profile to discuss 1-to-1.

        Thank You,
        Dhanik

        Reply
    5. J S Deepthi on September 29, 2021 6:04 am

      Error during LWC component connect phase: [Cannot read properties of undefined (reading ‘0’)]. I am getting this error

      Reply
      • Dhanik Lal Sahni on December 7, 2021 12:59 pm

        Hey Deepthi,

        Please check property name in js. If your property name is objectApiName then it will be added as object-api-name. If it is created as objectAPIName then use like object-a-p-i-name in template attribute. Character Casing impact usage in the template. So please check and update the code accordingly.

        Thank You,
        Dhanik

        Reply
    6. Laxmi on October 7, 2021 10:59 pm

      Error during LWC component connect phase: [Cannot read properties of undefined (reading ‘0’)]
      I am getting above error.
      function – DynamicTable.connectedCallback
      Please help

      Reply
      • Dhanik Lal Sahni on December 7, 2021 12:53 pm

        Hello Laxmi,
        Looks like you are not passing the columnList from the caller component. This should be passed otherwise you will get this error. Alternatively, you can add code for null and undefined check in connectedCallback method for columnList attribute.

        Thank You,
        Dhanik

        Reply
    7. Morgan Paboeuf on October 26, 2021 9:34 pm

      Hello,
      I have to build a table with 5 columns, one of which is a combobox, I have trouble making my rows communicate with each other, for each row I have to retrieve the values of the other columns and those selected in my combobox, how do I go about doing this? can you please help me? I have already spent enough time on this and I am having trouble realizing it

      Reply
      • Dhanik Lal Sahni on October 27, 2021 10:07 am

        Hello Morgan,

        In component InputPickListCell raise event with selected value to caller component. Caller component will handle event and based on row selected it should populate values in other fields. In each row, we are storing uuid which will help you in retrieving the selected row.

        Thank You,
        Dhanik

        Reply
    8. Pingback: Dynamic Record Page Creation using FieldSet | SalesforceCodex

    9. vivek dongardive on December 28, 2021 11:28 am

      Hi sir, how to display existing record in account and below that add new row button. i am able to get add row button but not able to get existing record.

      Reply
      • Dhanik Lal Sahni on December 29, 2021 9:57 am

        Hello Vivek,

        Have you tried to debug the issue? Is there any error in the console log? Please check and confirm.
        We can discuss this on call, if required.

        Thank You,
        Dhanik

        Reply
    10. Raghu on November 29, 2022 11:37 am

      Hi Dhanik,

      I am working on a similar requirement to this topic, the ask is to display custom picklist in data and make it editable to inline edit. I would like know if you are available to assist. If you can let me know the best time/way to connect.

      Reply
      • Dhanik Lal Sahni on November 29, 2022 7:40 pm

        Hello Raghu,

        Yes, let us connect on linked-in.

        Thank You,
        Dhanik

        Reply
    11. Bhupal on January 25, 2023 10:35 pm

      No MODULE named markup://c:inputTableCell found : [markup://c:dynamicTable]

      I am getting this error , I am not able to figure the error.
      Please help me .

      Reply
      • Dhanik Lal Sahni on February 7, 2023 9:12 pm

        Hello Bhupal,

        Looks like you have not created LWC inputTableCell or given a different name for that. Please check this component is exist in your application. If not, create and try once again.

        Thank You,
        Dhanik

        Reply
    Leave A Reply Cancel Reply

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • 10 Salesforce Chrome Extensions to Boost Your Productivity
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • Top 20 Salesforce Data Cloud Interview Questions & Answers for Admins June 5, 2025
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    Archives
    Categories
    Tags
    apex (111) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code analysis (3) code optimization (8) custom metadata types (5) design principle (9) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (65) lightning-combobox (5) lightning-datatable (10) lightning component (31) Lightning web component (63) lwc (52) named credential (8) news (4) optimize apex code (4) optimize apex trigger (3) Permission set (4) pmd (3) Queueable (9) rest api (23) S3 Server (4) salesforce (142) salesforce apex (47) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Facebook X (Twitter) Instagram Pinterest YouTube Tumblr LinkedIn Reddit Telegram
    © 2025 SalesforceCodex.com. Designed by Vagmine Cloud Solution.

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

    Ad Blocker Enabled!
    Ad Blocker Enabled!
    Our website is made possible by displaying online advertisements to our visitors. Please support us by disabling your Ad Blocker.