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
Sudipta DebSudipta Deb 

Batch class to prepare csv file and send it to ftp server location

Hi,

I have a requirement where I need to run a batch class (Frequency: Weekly) which will generate a csv file and put the file to a ftp server. Do you have any idea how can I achieve the same? Thanks.

With regards,
Sudipta Deb
pconpcon
Generating a CSV file for export via Apex is pretty straight forward [1].  The problem is going to be that you cannot directly interact with an FTP system via Apex.  I would suggest that you try to setup a web application that you can do a POST call to and that saves your CSV file to disk.  I would also recommend reviewing the asyncronous apex [2] and integration [3] trailheads.

[1] http://www.salesforcetutorial.com/how-to-export-data-in-csv-by-using-apex-code/
[2] https://developer.salesforce.com/trailhead/module/asynchronous_apex
[3] https://developer.salesforce.com/trailhead/module/apex_integration_services
Osvald MarkusOsvald Markus
I guess you can also use Skyvia (https://skyvia.com/data-integration/salesforce-data-loader) (no-coding way) to run the process which will generate a CSV file and put to FTP. All you need is to set up the connections to your Salesforce and FTP accounts, map the necessary Salesforce fields to CSV file, and specify the scheduling time (weekly in your case).