function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
A GunaleA Gunale 

Using Aura how can we fetch record ids

Hello,
I have a component which has a list of Account records. I just want to collect all selected records ids and pass those to Apex class.

Thank you in advance!

List of Account records
Surender reddy SalukutiSurender reddy Salukuti

Hi ,
if its lightning Datattable then you can use like below 

 <lightning:datatable  onrowselection="{! c.handleRowAction }">

  handleRowAction : function(cmp, event, helper){
        var selRows = event.getParam('selectedRows');

in selrows variable you will get all the rows 

Suraj Tripathi 47Suraj Tripathi 47
Hi  A Gunale,
You can do it like this:
Component:
<lightning:datatable
            columns="{! v.columns }"
            data="{! v.data }"
            keyField="id"
            maxRowSelection="{! v.maxRowSelection }"
            onrowselection="{! c.updateSelectedText }"/>
Controller:
updateSelectedText: function (cmp, event) {
        var selectedRows = event.getParam('selectedRows');
        cmp.set('v.selectedRowsCount', selectedRows.length);
    }

you can take reference from this:
https://developer.salesforce.com/docs/component-library/bundle/lightning:datatable/example#lightningcomponentdemo:exampleDatatableBase
If you find your Solution then mark this as the best answer.  
Thank you!
 Regards,
 Suraj Tripathi 
A GunaleA Gunale
Thank you both of you for your quick response.