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
Lorant DobrondiLorant Dobrondi 

Best way to parse CSV file via Apex code

Hello,

I have been tasked to create a batch apex loader which parses a CSV file from an email attachment.

I will use an email handler to get the email with the CSV file attached, and then I will try to load the attachment, and go through it, and create a new object for each line in it.

The CSV file will be sent from an outside source, and it can contain a lot of long text in some of the columns. Even line-breaks, and quotes can appear in some of the columns.

Is there a good, readily available CSV parser class/library in APEX, that I could use? One that handles all the cases, where there could be separators, quotes, end of lines INSIDE a value? Also, I would like to be able to handle all kinds of international & special characters.

I don't want to re-invent the wheel, and spend a lot of time on writing & testing the parser, if there's something already out there.

Thanks