2

I have an excel file with a lot of records, and I need to import these records to a salesforce object by implementing a class and a visualforce page in order to use it in the future if needed. So, I don't need to work with data loader or import wizard

Is it possible to do that ? or should I stick with Data Loader ?

2
  • Is it the .xls, .xlsx, or .csv form of the data you are trying to import? Does your data have embedded line feeds?
    – Keith C
    Oct 13, 2014 at 13:20
  • Yes, it's a csv file. About the data, no it has no embedded line feeds @KeithC Oct 13, 2014 at 13:43

3 Answers 3

5

Providing the CSV files are not too big, you can use a Visualforce apex:inputFile to upload the file and then apply this Parse a CSV with Apex sample code to grab the data from the rows.

If the CSV files are large you will hit a governor limit such as the the 6M byte heap space or the 10 seconds of CPU or the 10,000 rows of DML.

3
  • It is actually quite easy to hit the governor limits with either wide or long CSV files. I would recommend planning for a batch process to process a large file. Oct 13, 2014 at 14:05
  • it's actually a big file "32,000 record". Could I separate the file into 4 files and use the first way ? Oct 14, 2014 at 8:24
  • @HasanKhatib As Jeremy mentions the width - how many columns/characters per line also matters. But yes you could break the file up into pieces.
    – Keith C
    Oct 14, 2014 at 8:46
1

You need to use <apex:inputFile> to upload file, then you can use apex to parse input file. For more details you can check following link:

Import csv file using apex visualforce

http://www.sfdcpoint.com/salesforce/import-csv-file-using-apex-visualforce/

0

The article Importing large CSV files via Batch Apex can be useful when the CSV is large. It splits the CSV into iterable lines and the processes them as a batch using Marty Y. Chang's IETF RFC 4180-compliant CSV Reader.

This approach can help when keep within the heap size limits.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.