Delete Multiple Records Using Checkbox

Delete Multiple Records Using Checkbox In Lightning Component

Lightning Component

Sharing is caring!

Delete Multiple Records Using Checkbox

In this post we are seeing that how to delete multiple records using checkbox in salesforce lightning components. also, showing error alert message, if any record dependent to other records.

Delete Multiple Records Using Checkbox

Prerequisites : basic understanding of Lightning Component. And apex Programming.
Step  1 : Create Server Side Apex Controller.

DeleteWithCheckboxController.apxc

  • For this post i have use standard contact object.
  • See code comments.
Step 2 : Create Custom  Lightning Component.

DeleteWithCheckboxComponent.cmp 

  • In the above component code, we iterate all contact record with checkbox and store the record id in ui:inputCheckbox  text attribute on line number 58 [text=”{!con.id}”} ].
  • See code comments.
DeleteWithCheckboxComponentController.js

  • See code comments.
DeleteWithCheckboxHelper.js

  • See code comments.
TestApp.app

  • After the winter 17 release you can  use the Lightning Design System style in Lightning Apps by extends=”fore:slds”.  The Salesforce Lightning Design System provides a look & feel that’s consistent with Lightning Experience. Use Lightning Design System styles to give your custom applications a UI that is consistent with Salesforce.

Delete Multiple Records Using Checkbox

Some Useful Resources : 

ui:inpuitCheckbox

Delete Result Class

Lightning design style checkbox

https://www.lightningdesignsystem.com/components/data-tables/

Like our facebook page for new post updates.? & Don’t forget to bookmark this site for your future reference. ?

if you have any suggestions or issue with it, you can post in comment box  🙂

Sharing is caring!

(Visited 7,324 times, 14 visits today)

22 comments

      • Hi ,

        When I am trying to put this component on a lighting page layout , I am getting this error message :

        “Unfortunately, there was a problem. Please try again. If the problem continues, get in touch with your administrator with the error ID shown here and any other related details. This page has an error. You might just need to refresh it. Action failed: c:DeleteWithCheckboxComponent$controller$doneWaiting [Cannot read property ‘style’ of null] Failing descriptor: {c:DeleteWithCheckboxComponent$controller$doneWaiting}”

        NOTE : with individual app it’s working fine

        can you please help me out on this

        thanks

  • Hi

    I’m getting one issue, if there is only 1 contact;

    And we select, SelectAll option, then the 1 contact is not getting selected.

  • How to Add Multiple rows in a Lighnting Component

    If you click (+) a new row with all data will be populated

     

  • I have a question. Where is the event registered? As you are using the event to get the value in selectAll method. Can you let me know where the event was registered in component?
    if possible can you post the event code too.

    • Basically this event is Standard Lightning event binding with ‘event’ parameter in method it, means we are getting the value of that particulate Header checkbox which is selected and on the selection this ‘selectALl’ method will be fire, if it will be true then ‘event.getSource().get(“v.value”);’ return true if it false then it will be return false, simple 🙂
      Hops it helps

  • Cool. Thanks for the explanation.
    Suppose if the checkbox is selected then only we need to display the Delete Contact button as a separate component but not on the header. If checkbox is not selected then the Delete contact button should not be displayed.
    I mean to say instead of a button here can we create a panel component to display the Delete contact button depending on the checkbox selected or not instead of displaying it on the header everytime.

    Can you let me know how to do this and how to communicate between the components when doing this? Appreciate if you can post a code for this.

  • Hi..This doesn’t work with one record. component.find() is not working if their is only one record in the table. Try limiting the record to 1 and see if it works.

  • Hi Piyush,

    I need to check some records accordingly and i have to download only the checked records not all records. Is it possible you can share me some relevant code.

    Many thanks.

  • Hi Piyush,

    I need to query records from oportunity with checkbox next to each records. The functionality is, suppose I select 3 checkboxes i.e 3 records, I need to download detail pages of those 3 selected records by keeping a custom button. I need to achieve this functionality in lightning. Can you pls help with code.

Leave a Reply