+ Start a Discussion
Rey ChangRey Chang 

Schedule Class to read csv files

Hello All, 

    I am looking at developing a schedule class which can read csv files and insert salesforce records . I am aware of the way , it can be done with the help of a visualforce page, but is there a way in which it can be done without that ? 

Thanks 
Rey
Best Answer chosen by Rey Chang
Shamsher SinghShamsher Singh

Rey Chang:  There are many ways. Scheduler class to read a file and create salesforce records - i am assuming it wont be real time. In case of VF Page scenarion it has to be real time if you are uploading from system.

Solution 1:
1. You can store the csv file in any custom object(as an attachment).
2. Schedule the class to read the csv file from custom object.
3. Write your logic in helper class to create the salesforce records.
4. Have a marker on the csv file(custom object) that it has been processed. (If on custom object, have a checkbox to mark it to true once the scheduler finishes.)

.csv file must be in a format to read the fields value and map it to the object to create the records. Best is to provide a template to download in salesforce and fill your data and upload.

Hope it helps.

All Answers

ANUTEJANUTEJ (Salesforce Developers) 
Hi Rey,

I have found a similar query and there are certain implementations please  have a look and improve it in a way to comply with your scenario:

>> https://developer.salesforce.com/forums/?id=906F00000008n0zIAA

In case if this helped you can you please choose this as the best answer so that it is useful for others.

Regards,
Anutej
Shamsher SinghShamsher Singh

Rey Chang:  There are many ways. Scheduler class to read a file and create salesforce records - i am assuming it wont be real time. In case of VF Page scenarion it has to be real time if you are uploading from system.

Solution 1:
1. You can store the csv file in any custom object(as an attachment).
2. Schedule the class to read the csv file from custom object.
3. Write your logic in helper class to create the salesforce records.
4. Have a marker on the csv file(custom object) that it has been processed. (If on custom object, have a checkbox to mark it to true once the scheduler finishes.)

.csv file must be in a format to read the fields value and map it to the object to create the records. Best is to provide a template to download in salesforce and fill your data and upload.

Hope it helps.

This was selected as the best answer