Sub topic 13
Running Data Loader from the command line
This chapter assumes you can already run an insert or update in the Data Loader interface and have a saved field mapping. Command-line mode repeats that same job without anyone clicking through the wizard. That makes it useful for nightly loads, scheduled exports, and repeatable migrations.
What command-line mode needs
A command-line run replaces each screen of the interface with a file or an argument:
| Interface step | Command-line equivalent |
|---|---|
| Log in | Encrypted credentials in the configuration |
| Choose operation and object | `process.operation` and `sfdc.entity` |
| Choose the CSV | `dataAccess.name` and `dataAccess.type` |
| Map fields | A mapping file (`.sdl`) |
| Save result files | `process.outputSuccess` and `process.outputError` |
The jobs are defined in a file named process-conf.xml. The settings that apply to every job, such as batch size, live in config.properties. Each job is a "process" with a name, and you run it by that name.
Step 1: Encrypt the password
Never put a plain-text password in process-conf.xml. Data Loader includes an encryption utility, encrypt.bat, in its bin folder. First generate a key file, then encrypt the password with it.
encrypt.bat -k C:\dataloader\key.txt
encrypt.bat -e "MyPasswordSECURITYTOKEN" C:\dataloader\key.txtThe second command prints an encrypted string. With username and password login, the password value is your password followed directly by your security token. Salesforce has been moving orgs toward OAuth, so check which login method your version of Data Loader and your org support.
Step 2: Define the process
Save a mapping file with one CSV column=Salesforce field line per column:
Name=Name
Phone=Phone
Industry=Industry
Website=WebsiteThen define the job in process-conf.xml. This one inserts accounts into a sandbox:
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="accountInsert" class="com.salesforce.dataloader.process.ProcessRunner" singleton="false">
<description>Insert accounts from a CSV file.</description>
<property name="name" value="accountInsert"/>
<property name="configOverrideMap">
<map>
<entry key="sfdc.endpoint" value="https://test.salesforce.com"/>
<entry key="sfdc.username" value="[email protected]"/>
<entry key="sfdc.password" value="PASTE_ENCRYPTED_VALUE_HERE"/>
<entry key="process.encryptionKeyFile" value="C:\dataloader\key.txt"/>
<entry key="sfdc.entity" value="Account"/>
<entry key="process.operation" value="insert"/>
<entry key="process.mappingFile" value="C:\dataloader\accountMap.sdl"/>
<entry key="dataAccess.type" value="csvRead"/>
<entry key="dataAccess.name" value="C:\dataloader\accounts.csv"/>
<entry key="process.outputSuccess" value="C:\dataloader\out\success.csv"/>
<entry key="process.outputError" value="C:\dataloader\out\error.csv"/>
</map>
</property>
</bean>
</beans>For an export, set process.operation to extract, set dataAccess.type to csvWrite, and add a sfdc.extractionSOQL entry containing your query.
Step 3: Run it
Pass the folder that holds your configuration files, then the process name:
process.bat C:\dataloader\conf accountInsertWindows Task Scheduler, or cron where your version provides shell scripts, can run this command on a schedule. Look in your installation's bin folder to see which scripts your version ships.
Common errors
- Login fails. The security token is missing from the encrypted password, the endpoint is wrong (
test.salesforce.comfor sandboxes,login.salesforce.comfor production), or the key file differs from the one used to encrypt. - Process not found. The name in the command must match the bean
idand thenameproperty. - Job runs but rows fail. Read the error file after every run. An unattended job that nobody reviews will fail without anyone noticing.
Exercise
Your scheduled job runs without errors on screen, but some accounts are missing in Salesforce. Which output should you check, and which setting names it in process-conf.xml?
Show answer
Check the error file, which lists each failed row with its message. It is set by the process.outputError entry. The success file (process.outputSuccess) shows which rows did load.