收藏Pooja Nekkalapudi (William Blair and Company) 提问于 #Lightning Experience2023年4月26日 02:35How to update selected records in LWC by passing selectedRow IDs into a button that updates status field on each recordLWC.jsgetSelectedRec() { var selectedRecords = this.template.querySelector("lightning-datatable").getSelectedRows(); if(selectedRecords.length > 0){ console.log('selectedRecords are ', selectedRecords); let ids = ''; selectedRecords.forEach(currentItem => { ids = ids + ',' + currentItem.Id; }); this.selectedIds = ids.replace(/^,/, ''); this.lstSelectedRecords = selectedRecords; alert(this.selectedIds); } } async handleChange() { let records = this.template.querySelector('lightning-datatable') .getSelectedRows().map( // Converts the Array to desired field updates (record) => ({ ...record, [STATUS_FIELD.Role__c]: 'Actively Prospecting', sobjectType: OBJECT_NAME.Coverage_Team__c }) );await updateRecords({ records }); }LWC.html <lightning-button variant="Neutral" label="Selected Records" title="Selected Records" onclick={getSelectedRec} slot="actions" icon-name="utility:check"> </lightning-button> <lightning-button variant="Neutral" label="Update Records" title="Update Records" onclick={handleChange} slot="actions"> </lightning-button> <div style="border-top: 1px solid rgb(221 219 218);"> <!-- datatable --> <lightning-datatable key-field="id" data={data} columns={columns} column-widths-mode="fixed"> </lightning-datatable> <!-- /datatable --> </div>Apex controller:public with sharing class PA_WBTeam { @AuraEnabled (cacheable=true) public static List<Coverage_Team__c> getTeam(){ return [SELECT Actively_Prospecting_Team__c,Company__c,Contact_Status__c,Employee__c,Id,Location__c,My_Coverage_Team__c,Role__c,Sponsors__c,Status__c,Website__c FROM Coverage_Team__c WHERE Role__c='Suggested by ML Model' AND My_Coverage_Team__c = 'true' ]; }@AuraEnabled public static void updateRecords(Coverage_Team__c[] records) { update records; } }显示更多3 个回答排序按日期排序按最有帮助排序按日期排序加载更多评论...Pooja Nekkalapudi (William Blair and Company)2023年4月26日 14:31@Donald, My code does that but cant get it to update records添加评论撰写回答...粗体斜体下划线删除线项目符号列表编号列表添加链接代码块插入图像附加文件链接 URL取消保存0/9000回复
Pooja Nekkalapudi (William Blair and Company)2023年4月26日 14:31@Donald, My code does that but cant get it to update records