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
Ramesh T N 9Ramesh T N 9 

How to read csv file using Batch Apex class with using VF Page

Hi,

I have requirement to read csv file using Batch Apex without using VF page.
Could you please anyone help me with Batch Apex code.

Thanks and Regards,
Ramesh
PratikPratik (Salesforce Developers) 
Hi Ramesh,

You can refer to this post.

https://developer.salesforce.com/forums/ForumsMain?id=906F00000008v0tIAA

Thanks,
Pratik
Ramesh T N 9Ramesh T N 9
Hi Pratik,

Thanks for your quick response!!

I was seen post mentioned by you, but they are reading csv file using VF page tag. 
<apex:inputFile value="{!contentFile}" filename="{!nameFile}" />

My requirement is to read csv file from my local or server machine directly from Apex code.

Best Regards,
Ramesh
Andreas MeyerAndreas Meyer
Hi Ramesh,

you cannot read local files with a apex batch job form you local machine, thats why you need a VF page to upload this file. Therefore the only option is to have those files on a server or as  attachments on a custom object.

In general i don't see the need to use a batch job for that. Apex batch jobs are meant for processing huge amount of already persisted data (in SFDC) that cannot be done in a single execution of a apex class. 

So why don't you use the Data Import Wizard or DataLoader to import your csv file(s). If you really have a lot of csv files on a server which are dynamically added by another process a scheduled job is the better approach. 
Again: The batch job split up a huge number of SFDC objects you receive by a query but do not split up the lines in a huge csv file or even processes a large amount of server sided csv files in defined portions.

But maybe i just don't understand your requirements.

Best,
Andreas