[SalesForce] How to parse large size csv file content into custom object in Salesforce

I have requirements to implement the LWC file upload wizard which should handle very large size csv file( about 1 GB).. is it doable to parse such large size csv through APEX batch method?

I tried it after googling some help and it seems like, it reach to heap size limit. is there any work around for this problem?

Appreciate if someone can guide with sample code snippets or sample.

NOTE: Tried with but no luck https://developer.financialforce.com/customizations/importing-large-csv-files-via-batch-apex/

Thanks in advance !

Best Answer

No, Apex won't handle 1GB. A single string can be at most heap size in length (12MB for Batch Apex). Since you're using LWC, process the file client-side and pass the data in chunks to Apex. If you anticipate files of this size, you will want to read the file in chunks using File.slice as demonstrated in this Stack Overflow answer.

Related Topic