我正在尝试从FOR循环强制向Apex发出多个标注。但奇怪的是,只有前6笔交易取得了成功。其余的都失败了。开发人员文档中没有提到从LWC到Apex的标注数量限制。
采用这种方法的原因是每个标注都将遵循一组新的Apex限制。
import { LightningElement, api, wire, track } from 'lwc';
import insertRecords from '@salesforce/apex/FileUploaderXCtrl.insertRecords';
export default class FileUploadExample extends LightningElement {
file;
filename;
filecontent;
output = [];
buttonVisible = false;
position = 0;
get acceptedFormats() {
return ['.csv'];
}
uploadFiles(event) {
console.log('Hey! No of Callouts: ----------->' + this.output.length);
for (let index = 0; index < this.output.length; index++) {
console.log('Making Callouts Now! Watch Out --------');
insertRecords({ jsonObjInput: this.output[index] })
.then(() => { console.log('*******\n\nHurray! Its Working....\n\n********'); })
.catch((error) => { console.log('Go Home...'); });
}
}
handleUploadFinished(event) {
if (event.target.files.length > 0) {
this.filename = event.target.files[0].name;
this.file = event.target.files[0];
var reader = new FileReader();
var jsonObj = [];
reader.readAsText(this.file, "UTF-8");
reader.onload = (evt) => {
console.log('File Name: ----------->' + this.filename);
this.filecontent = evt.target.result;
let rows = this.filecontent.split('\n');
let header = rows[0].split(',');
rows.shift();
console.log('Header: ----------->' + header);
rows.forEach(element => {
let data = element.split(',');
let obj = {};
for (let index = 0; index < header.length; index++) {
obj[header[index].trim()] = data[index].trim();
}
jsonObj.push(obj);
});
let result = new Array(Math.ceil(jsonObj.length / 10000)).fill().map(_ => jsonObj.splice(0, 10000));
result.forEach(element => {
this.output.push(JSON.stringify(element));
});
console.log('Apex Input Parameter: ----------->' + this.output);
console.log('No of Callouts: ----------->' + this.output.length);
}
reader.onloadend = (evt) => {
this.buttonVisible = true;
}
reader.onerror = (evt) => {
if (evt.target.error.name == "NotReadableError") {
console.log('An Error Occured Reading this File!!');
alert('An Error Occured Reading this File!!');
}
}
}
}
}发布于 2020-08-25 03:07:41
stackexchange上已经有几篇关于这方面的好文章了。这就是所谓的boxcarring,由于浏览器能够限制并行调用的数量,lwc会执行boxcarring。
https://salesforce.stackexchange.com/questions/293025/boxcaring-is-removed-from-lwc-components
您应该在“为什么salesforce在lwc中使用boxcarring”下查看它们。
简而言之,您可以选择异步使用promises来避免这些,否则其他解决方法将是setTimeout。
这两种方法都不会提供很好的用户体验,相反,您应该探索其他替代方法来实现这一点,包括以下内容
在Heroku等应用程序上,
https://stackoverflow.com/questions/63560998
复制相似问题