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 upload file automatically


There is a feature requirement in our application, that requires file to be uploaded on server just by clicking a button.

Is there any option in Apex/ Visualforce/SControls using which we can upload file automatically. Any technique, wether using Javascript/ AJAX.. would do.. its urgent??

Thanks in Advance.


Nazeer AhamedNazeer Ahamed
You can use Notes and Attachments object..right?
When you say "upload", do you mean "import" -- as in loading data into a standard or custom object?

Also, where is the file located? On the user's computer? Is the filename and location always the same?

This sounds similar to something I am trying to do.

I am trying to import 300+ CSV files automatically into a custom object. These can be housed on a user PC or a server or document library on a sharepoint site, which ever is easiest to get the functionality.

I would suggest using DataLoader in batch mode.

You could pass the filename in as a command-line parameter, so just get something (eg command line script) to iterate through the files, calling DataLoader once per filename. The rest of the configuration (eg field mapping, login information) would be stored in the DataLoader configuration files and be used automatically for each batch.

The Data Loader PDF manual is pretty good, but I'd be happy to answer any specific questions. I use it quite a bit in batch mode.
Thanks John, Ill take a look at it and see what I come up with.
I have been looking at the data loader and running it on the command line. I have been able to get it to import one file but I do not know how i would write a script to get it to call each file name with the dataloader. It seems to me that the file is embedded in the config file. If you had an example that may help me :) Thanks 
Hi MDGonz,

I load multiple files in the DataLoader by calling it once per file, eg:

java -cp bin/DataLoader.jar com.salesforce.dataloader.process.ProcessRunner
java -cp bin/DataLoader.jar com.salesforce.dataloader.process.ProcessRunner
java -cp bin/DataLoader.jar com.salesforce.dataloader.process.ProcessRunner

For each of those "processes", I have an entry in process-conf.xml and a matching query in database-conf.xml. I load data from a database, not a file but you could just as easily include the filename in the process-conf.xml file.

Alternatively, you can pass parameters on the command line. I haven't done it, but I've seen it somewhere. For example:

java -cp bin/DataLoader.jar com.salesforce.dataloader.process.ProcessRunner"Contacts77.csv"




Thanks for the help, let me take a little time and look this over and try a couple things out and see where I end up.

poonam wadhwani 13poonam wadhwani 13
Hi MDGonz,

Can we upload this csv automatically to Chatter File using Data Loader?

My requirement is to make this csv available for public user even outside salesforce.

Any help would be appreciated.Thanks!