Sunday, June 22, 2014

Apex Data Loader in Linux

Salesforce Apex Data Loader is only officially supported on the Windows platform but the source code is available as an open source project for anyone to build it for another platform such as Linux or Mac. The data loader is written in Java using the Spring Framework so it can be easily rebuilt for any platform that supports the JDK and corresponding Eclipse SWT for GUI. If you don't care much for the GUI to do the mapping and simply want to use it from the command-line, then the good news is that the same JAR file from the Windows installation can be used to run the process in another platform without having to rebuild the code.

What's missing however are the Linux version of the utility scripts (in the bin\ directory in windows installation) to do the password encryption and process execution. I recently had to execute the data loader jobs from Linux and ended up writing the missing scripts so it is easy to mimic the Windows command line process (as explained in Chapter 5 in the guide).

The code is on github and includes the default configuration options and a sample extract process. The directories mirror the Windows version and the following steps walk you through the process:
  1. From your Linux (or Mac) terminal, execute the following command to clone the project from github
     $ git clone https://github.com/sthiyaga/dataloader.git 
  2. Copy the dataloader-30.0.0-uber.jar from the Windows installation to dataloader/ directory (from above)
  3. Generate the private key to encrypt the password 
    $ bin/encrypt.sh -g <some-random-seed-text>
  4. Copy the output from Step 3 above to the file conf/private.key (replacing the text in there)
  5. Encrypt the salesforce password (+security token, if required) using the generated private key 
    $ bin/encrypt.sh -e "password+securitytoken" conf/private.key 
  6. Copy the output from Step 4 above to the conf/config.properties file for the sfdc.password token value
  7. Update the conf/config.properties file with sfdc.username and sfdc.endpoint token values
  8. Optionally, adjust any other default parameters in the conf/config.properties file
  9. Run the sample account extract process 
    $ bin/process.sh csvAccountExtractProcess
That's it, you should have the sample extract in the data/ directory.

Enjoy and feel free to use the code!

-Senthil

1 comment:

  1. Thanks Senthil. The documentation here and the scripts worked great for me.

    ReplyDelete