I am looking for an approach to perform the below:
[1] Read an CSV file from the local drive and insert the contents into SFDC (having a typical Browse button)
[2] Once the read is complete upload the CSV into Content
[3] Locally create an Error Log with the failed rows and error message (or) Write into the same CSV file the Error against each failed row
The design I am thinking off is to have a VF Page with Java Script to locate and read the rows while the Controller would do the insert. Is this design viable? If not what would be the best approach?
Best Answer
Good question, I personally would not try to handle this in the client, it's to fragile an environment, better to upload this file and handle at the server side. Or consider adjusting your requirements / user expectations to fit Salesforce Data Loader tools, see my summary below.
Client Side
Server Side
The following should get you started on a number of things you need to address here.
Summary and Salesforce Data Loaders
Parsing CSV files can be very expensive on Apex statements, which will limit the size and complexity of the files you can consume. So you should consider if you really need to build this yourself vs either of the Salesforce Data Loaders (there is a desktop and web based version). Neither of these however will retain the CSV file uploaded unfortunately, so if that is a strict requirement then rolling your own is the way to go.
Hope the above helps give you the pointers you need, enjoy!