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.