1

This might seem very simple on the surface, but I am wondering why won't the updateRecordApi take a list of records to be updated at once? The documentation says that it would take only one record at a time to be updated.

I have a requirement where a particular trigger point on one record (through LWC) requires many other records to be updated. If I have to update say 10 records without using apex, would I need to hit the udpateRecordApi 10 times in a loop? Won't it have performance or governor limit issues?

If I have to use apex, would I need to pass a JSON string with updated field values for each record and then map in apex and invoke the DML?

Any help much appreciated. Thanks!

1
  • Because Salesforce. I am also disappointed that it isn't possible at the moment. Maybe will have it in the future. I would advise to go through Apex if you need a list update with AllOrNone set to true. Otherwise loop in front is okay as the LDS is making bulk calls (grouping the several calls). Make sure to use Promise.all in such case. Commented Apr 4, 2022 at 16:36

2 Answers 2

1

why won't the updateRecordApi take a list of records to be updated at once?

lightning/ui*Api wire adapters and functions are built on top of Lightning Data Service (LDS) & User Interface API, with the primary objective of facilitating quick custom UI building. LDS & UI API currently support record, lists and app level functionality in a limited way. updateRecordApi was built only to handle single record (considering the usage on lightning base components lightning-record-*-form).

If I have to update say 10 records without using apex, would I need to hit the udpateRecordApi 10 times in a loop? Won't it have performance or governor limit issues?

Don't call this in a loop unless you have a valid use case (esp., if you are going to update related records in one go). While each of this callout to apex will be a discrete transaction, it will have major inconvenience from a user experience perspective and lead to poor performance overall at application level.

If I have to use apex, would I need to pass a JSON string with updated field values for each record and then map in apex and invoke the DML?

Yes, you need to do this. Create a @AuraEnabled apex that can parse the JSON and perform DML (esp., if you are going to perform DML on multiple different object). If you are going to be update multiple records of a single object, you can pass an List<SObject>. Refer to few sample codes for passing SObject from LWC here & here. For passing List<SObject>, you have to pass an array from JS.

1

Instead of calling updateRecord in a for loop, use Promise.all. In the new lwc recipies for lightning-datatable you can find some examples. Look at this one.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .