function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rahul MehataRahul Mehata 

Lwc file uploaded issue

Hello,

I have written below code to upload csv file. It's getting uploaded but I can see blank row spaces after record in org.

import { LightningElement, api } from 'lwc'; import executeBulkInsert from '@salesforce/apex/FileUploadController.executeBulkInsert'; import TRAILHEAD_CHARACTERS from '@salesforce/resourceUrl/SampleFiles'; export default class BulkInsert extends LightningElement { value = ''; handleChange(event) { this.value = event.detail.value; } @api sobjectName = 'Case'; statusMessage = ''; FileUrl = 'Sample CSV File' + '/SampleFile/BulkLoad.pdf'; readCSVFile() { console.log('readFiles'); [...this.template.querySelector('input[type="file"]').files].forEach(async file => { try { const csvResult = await this.load(file); console.log('csvResult ' + csvResult); // Process the CSV here if(csvResult != null) { executeBulkInsert({ csvResult: csvResult, sobjectName: this.sobjectName }) .then((result) => { this.statusMessage = result; console.log('final result', this.statusMessage); this.error = undefined; }) .catch((error) => { console.log('error from apex: ' + error); this.error = error; }); } } catch(e) { // handle file load exception } }); } async load(file) { return new Promise((resolve, reject) => { const reader = new FileReader(); console.log('file: ' + file); reader.onload = function() { resolve(reader.result); console.log('resolve: ' + reader.result); }; reader.onerror = function() { reject(reader.error); console.log('reject: ' + reader.error); }; console.log('abcd',reader.result); reader.readAsText(file); }); } }
VinayVinay (Salesforce Developers) 
Hi Rahul,

Seems like we need more details on this,  Check below working examples.

https://www.sfdcpoint.com/salesforce/file-upload-in-lightning-web-component/
https://www.salesforcetroop.com/custom_file_upload_using_lwc

Thanks,