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

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


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


I have used this code and modified to my usage, this works simply great




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.





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



Shivani DesaiShivani Desai
Hi Urvi,

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