Although the Salesforce Data Loader is primarily known as a GUI based tool for exporting/importing data it can be used via command line also.
First thing you have to do is download Salesforce Data Loader. It will be under the location C:\ProgramFiles\salesforce.com\DataLoader
Salesforce Data Loader Commands :
Navigate under C:\ProgramFiles\salesforce.com\DataLoader/bin and type dir. Two commands are listed:
• process
• encrypt
The syntax for those commands are :
• process (config_dir_path) (process)
• encrypt –e (string to encrypt)
where (config_dir_path) is a directory that contains 2 files:
• config.properties
• process-conf.xml
and (process) refers to a section (called a “bean”) in the process-conf.xml file.
The next section describes how to populate and configure those two files for running the process command.
The encrypt command can optionally be used to encrypt passwords stored in the process.properties files but the next section will show that the encryption can also be done through the GUI based Salesforce Data Loader.
Prepare a work directory :
Create a working directory with the following sub-directories: conf, dataexp, dataimp, log (this is not mandatory and the naming can be changed but it is a best practice to structure data loader work this way).
Prepare the config.properties file
Open the Salesforce Data Loader set the settings to a target organization.
Leave the other parameters by default for now.
Then click on any command button to logon.
(Note that the password must be the username password followed by the security token).
Once the login has been validated, navigate to the Salesforce GUI Data Loader roaming directory (this directory can be found by right clicking on the Salesforce Data Loader Icon and displaying the property. Looking for the value of the appdata.dir parameter:
Under the user roaming directory navigate under salesforce.com. From this directory copy the config.properties to the work directory.
Below is an example of config.properties file. Note that the GUI tool has encrypted the passwords provided in the UI. Other interesting parameters are statusOutputDirectory which controls log directory and statusOutputDirectory and outputError which control the success and error log file name (if not provided the Data Loader default to a timestamped name).
Config File looks like :
#Loader Config
#Wed Aug 02 18:44:16 CEST 2014
sfdc.endpoint=https\://login.salesforce.com
sfdc.username=mansi.tha@example.com
sfdc.password=52b2f005930xxxxxxxxxxxxxxxxxxxxxxxxxxxe22bc2d0d4434
sfdc.proxyNtlmDomain=AD
sfdc.proxyHost=proxy
sfdc.proxyUsername=user
sfdc.proxyPort=8080
sfdc.proxyPassword=cxxxxxxxxx3098
process.statusOutputDirectory=C:\\work2\\log
process.outputError=C:\\work2\\log\\error.log
process.outputSuccess=C:\\work2\\log\\success.log
sfdc.useBulkApi=true
dataAccess.writeBatchSize=500
sfdc.bulkApiSerialMode=false
process.loadRowToStartAt=0
dataAccess.readBatchSize=200
process.operation=extract
sfdc.resetUrlOnLogin=true
process.useEuropeanDates=false
sfdc.minRetrySleepSecs=2
sfdc.loadBatchSize=200
sfdc.connectionTimeoutSecs=60
sfdc.truncateFields=true
process.enableLastRunOutput=true
sfdc.insertNulls=false
sfdc.timeoutSecs=540
sfdc.timezone=Europe
sfdc.bulkApiZipContent=false
sfdc.maxRetries=3
dataAccess.writeUTF8=false
sfdc.enableRetries=true
sfdc.bulkApiCheckStatusInterval=5000
process.enableExtractStatusOutput=false
Encrypt passwords in the config.properties file :
For regenerating a password either use again the Data Loader GUI to login and get the generated password in the roaming file or use the encrypt command:
encrypt –e <string to encrypt>
Copy the output to the config.properties file.
Prepare the Process-conf.xml :
The process-conf.xml cannot be generated. The easiest way to build one is to start from an example and adapt as needed. The example below shows a process-conf.xml file that can be used to do a basic export:
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="exportaccount" class="com.salesforce.dataloader.process.ProcessRunner" singleton="false"&g
<description>exportAccount</description>
<property name="name" value="exortaccount"/>
<property name="configOverrideMap">
<map>
<entry key="sfdc.entity" value="Account"/>
<entry key="sfdc.extractionSOQL" value="Select Id, Name FROM Account"/>
<entry key="process.operation" value="extract"/>
<entry key="dataAccess.name" value="C:\\work2\\dataexp\\exportaccount.csv" />>
<entry key="dataAccess.type" value="csvWrite" />
</map>
</property>
</bean>
</beans>
Note the structure of the file: it contains a list of beans (in the example above there is only one bean). Each bean has an Id and name property that must be used to reference the bean in the process command.
The property sfdc.entity specifies the target object (Account, Contact, ….) for the Data Loader operation.
The property configoverrideMap and the map section below (re)define parameters already present of absent from the config.properties file (i.e.: if a property is defined both at config.properties level and bean level, the bean level value will override).
In the example above the bean can be called and executed by entering:
process C:\work2\conf exportaccount
This command will extract the ID and Name columns of Account where Name starts with A and write the results in csv format in the “C:\\work2\\dataexp\\exportaccount.csv” file.
Note that for import and delete (or upsert) it is necessary to provide a map file to map the input file columns with the target object. The map file can be created with the Data Loader GUI tool. Once created it can easily be updated and adapted manually