
Data Loader With Command Line
Problem – It is usually the requirement that we need some automated process that can automatically insert all the records into your Salesforce Org.
Solution – The possible solution is that we can achieve the solution to above problem by using the salesforce data loader command line. Note: – Command Line Data Loader is only supported for Windows. What is Data Loader or Data Loader CLI? Data Loader is a client application for the bulk import or export of data. We can use it to insert, update, upsert, delete, export or export all of the SalesForce records. When importing data, it reads then extracts, and then loads data from comma-separated values (CSV) files or from a database connection. When exporting data, it outputs the data as CSV files.

- User interface — when you use the user interface, select the required action, CSV files used for import and export, and the field mappings that map the field names in your file with the field names in Salesforce to prepare an SDL File.
- Command line (Windows only) — to make an automated process for data loader, when you use the command line, you have to specify the configuration i.e., data loader actions, data sources, mappings.
- Step 1: Create the encryption key
- Step 2: Create the encrypted password for the login username
- Step 3: Create the SDL(Mapping) File
- Step 4: Create a process-conf.xml file that contains the import configuration settings
- Step 5: Run the process and import the data
- Make sure you have downloaded data loader. If not, login to your Salesforce Org. Then Setup –> Data Management –> Data Loader. Choose the option “Download Data Loader for Windows “.
- Make sure you have the Admin rights on the machine.
- Also, you must have latest Java Run Time Environment. If not, you will have to download the Java Run Time Environment from Oracle site downloads page. Install the downloaded JRE file.

- Open your C drive, then migrate to “bin” folder within “Salesforce.com > DataLoader” folder.
- Open Command Prompt(cmd), and navigate to the bin folder of data loader directory as shown in the image below.
- Use the command “bat -g anyKeyTextOfYourChoice”. You can use any text you want to use as an Encryption key. Once you press enter, you will find a key, copy it and save it in a text file. For example, I saved my key in “E:\CLI Test\encryptionKey.txt”.
- For creating your encrypted password, firstly we need to get our org’s “Security Token”. Login in to your Salesforce org, then “My Settings -> Personal -> Reset My Security Token -> Click on Reset Security Token Button”
After this you will receive security token on your registered mail.
Save this security token for future reference as this will used for generating the encrypted password.
- Now on command prompt, enter following command: –
“encrypt.bat -e <yourOrgPassword> <location of the txt file with encrypted key>”“yourOrgPassword” will have to be the combination of your Org’s Password and the Security Token You Received in the mail.For example: – If My org’s password is “Test1234” and the security token I received on my mail is “iDIy7LozsaJDJ55A83i7qVpU”, and the path for my encrypted text file is “E:\CLI Test”.Then on command prompt: –
bat -e Test1234iDIy7LozsaJDJ55A83i7qVpU “E:\CLI Test\encryptionKey.txt”
Copy this encrypted value of your password. Save it also in a .txt file.


- Prepare a “process-conf.XML” and store it in same directory. For Example, I stored in “E:\CLI Test”.

- sfdc.endpoint—Enter the URL of the Salesforce instance for your organization
- sfdc.username—Enter the username Data Loader uses to log in
- sfdc.password—Enter the encrypted password value that you created in step 2
- process.encryptionKeyFile – Enter path for the encrypted key file(.txt)
- sfdc.entity – Enter the object on which you want to insert data
- process.operation – Enter the operation (insert, update, export) you want to perform, though here we have configured the “process-conf.XML” for insertion operation only.
- process.mappingFile—Enter the path of the file and file name of the SDL file for mapping that we just created.
- dataAccess.Name—Enter the path and file name of the data file that contains the accounts that you want to import(.CSV)
- sfdc.debugMessages— Currently set to true for troubleshooting.
- sfdc.debugMessagesFile—Enter the path and file name of the command line log file
- process.outputSuccess—Enter the path and file name of the success log file
- process.outputError—Enter the path and file name of the error log file



- Create a Batch File using the following code: –
- After cd, the path given is the path where the SalesForce – Data Loader has been installed.
- CALL “your.bat file” “Path of Batch file” “Process Name in Process-conf.xml”>
-
- Save the file with extension “.bat”.
- After saving, open Windows – Task Scheduler.






After the process is executed the command prompt with show the success and failure errors. You can also check the log files: “insertAccounts_success.csv” and “insertAccounts_error.csv”. Once the process executes correctly, the file “insertAccounts_success.csv” has ID and Status of all the records. Hence this is how we can automate the process of executing Data Loader using Command Line.