Background: There's a form where you select an id from a list, fill in some text input fields then hit save, this submits 1 record. The enhancement to this form is a multiselect LWC component which allows the selection of multiple Ids, for each Id selected they want a record submitted with the same text input fields filling out those records....
Here's the handleSubmit event
handleSubmit(event){
event.preventDefault();
this.getProduct();
this.isSubmitting = !this.isSubmitting;
for(let i=0; i<this._assetList.length; i++){
let fields = event.detail.fields;
fields.Theme__c = this._assetList[i];
fields.Toolkit__c = this.recordId;
fields.Quantity__c = -1;
this.template.querySelector('lightning-record-edit-form').submit(fields);
}
}
See how we're creating multiple records for all the values within _assetList.
Now the obvious problem where using a forloop to insert records again and again instead of a bulk insert. I was thinking of of modifying what i send as an argument to the submit() but i'm guessing its expecting a single sobject not a list of sobjects so before spending hours coding that out i was wondering if anyone here knew if it was possible.
If that isn't possible what suggestions does anyone have.
EDIT: update from conversion with the man himself below from what i know you can create one record using apex doing this
createRecord(event){
recList = [];
for(let i=0; i<this._assetList.length; i++){
let rec= { 'sobjectType' : 'Toolkit_LineItem__c'};
let fields = event.detail.fields;
rec.Price__c = fields.Price__c.value;
rec.Quantity__c = fields.Quantity__c.value;
rec.Theme__c = this._assetList[i]
rec.Toolkit__c = this.recordId;
recList.push(rec);
}
createRecLineItem({ newRecLine : recList});
}
passing to an apex method that takes an argument of sobject.....but how would i get an array of SOBJECT? edit: maybe the above will work, i'll find out.