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
prateek khanna 24prateek khanna 24 

Hi, I want to add bulk update operation on my data table on selected records, How can we achieve this ?

mukesh guptamukesh gupta
Hi Prateek,

youu can use below  apex code, if you working with lightning please let me know i will write  lightning component this code for check box
public class UpdateUsingCheckboxC {
    
    @AuraEnabled
    public static List <Contact> fetchContact() {
        return [SELECT Id, FirstName, LastName, Phone FROM Contact Limit 10];
    }
    
    @AuraEnabled
    public static void updateRecord(List <String> lstRecordId) {
        List<Contact> lstUpdate = new List<Contact>();
        for(Contact con : [SELECT Id, FirstName, LastName, Phone FROM Contact WHERE Id IN : lstRecordId]){
            con.Phone = '999999'; // Add fields which you want to update
            lstUpdate.add(con);
        }
        
        if(lstUpdate.size() > 0){
            update lstUpdate;
        }
        
    }
}

if you need any assistanse, Please let me know!!


Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh
prateek khanna 24prateek khanna 24
Yes , I am working with lightning data table and i want to add formula filed by some percent it should change all seleccted records in that filed.
Yogendra JangidYogendra Jangid
Hi Prateek, 
you can look at this documentation on how to use inline editing for bulk update using lightning datatable.
https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.data_table_inline_edit

If this answers your question, please can you mark this as best answer. Thanks.