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
AmbilyAmbily 

How to import data from .csv to Salesforce using Apex code?

Hi,

I have to export data from the .csv file( in a shared folder) to the corresponding fields in my Salesforce account using Apex code.

Kindly advice me how to achieve this...
Also share if some sample codes are available.


Thanks in Advance
Ambily

iffuiffu

I have used this code and modified to my usage, this works simply great http://www.forcetree.com/2010/08/read-and-insert-records-from-csv-file.html

 

Cheers!

UrviUrvi

Hi Iffu,

Have you checked for governer limits?

If my CSV contains more than 50k records then what is best way to use in this code example.

 

Please help me.

 

Thanks

Urvi

iffuiffu

Hi Urvi,

 

Yes, thats the important question but as I said, I only used the basic design of this program and modified it as per my usage. The CSV parser is good in it. Inorder to meet the governer limits, I used all of the data into Maps and minimised the use of SOQL and DML statements.

 

In your requirements, with a large data something like this, you can use batches to insert your data once you process it using CSV parser. You can find more about using batches here http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch_interface.htm

 

Cheers!

Shivani DesaiShivani Desai
Hi Urvi,

I am facing the same problem.Could you please help? What did you do to solve the problem?

Thanks,
Shivani