How to Setup Salesforce Dataloader CLI in Linux/Mac?

March 11, 2022
5 min read
By Syahmi Fauzi

Steps to setup dataloader CLI tool in Linux/Mac

  1. Clone the Project
Terminal
git clone https://github.com/mhamzas/Scripted-Data-Loader-for-Mac-Unix.git
cd Scripted-Data-Loader-for-Mac-Unix
  1. Create a folder dataloader and copy the latest dataloader-<version>-uber.jar file to it.
Terminal
mkdir dataloader
cp dataloader-<version>-uber.jar dataloader/
  1. Update ./bin/encrypt.sh and ./bin/process.sh with the correct version of dataloader-<version>-uber.jar file and make sure the first line in both files is #!/bin/bash.

  2. Give both files execute permission.

Terminal
chmod +x ./bin/encrypt.sh ./bin/process.sh
  1. Generate the private key to encrypt the password.
Terminal
./bin/encrypt.sh -k ./conf/myprivate.key
  1. Encrypt the Salesforce password and security token using the generated private key.
Terminal
./bin/encrypt.sh -e "<password><security_token>" ./conf/myprivate.key
  1. Copy the encrypted password and security token to the ./conf/config.properties file.

  2. Update the ./conf/config.properties file with the correct values.

./conf/config.properties
sfdc.username=<your_username>
sfdc.password=<your_encrypted_password>
sfdc.endpoint=<your_endpoint>
sfdc.debugMessages=true
process.encryptionKeyFile=conf/myprivate.key
# leave the other values as they are
  1. Replace the content of the following files with these values. Create the file if it does not exist.
./conf/process-conf.xml
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>

    <!-- EXPORT DATA FROM SALESFORCE -->
    <bean id="csvAccountExtractProcess" class="com.salesforce.dataloader.process.ProcessRunner" scope="singleton">
        <description>csvAccountExtract gets account info from salesforce and saves info into a CSV file.</description>
        <property name="name" value="csvAccountExtract" />
        <property name="configOverrideMap">
            <map>
                <entry key="sfdc.debugMessages" value="true" />
                <entry key="process.operation" value="extract" />
                <entry key="process.mappingFile" value="conf/accountExtractMap.sdl" />
                <entry key="sfdc.entity" value="Account" />
                <entry key="sfdc.extractionRequestSize" value="500" />
                <entry key="sfdc.extractionSOQL" value="SELECT Id, Name FROM Account LIMIT 5" />
                <entry key="dataAccess.type" value="csvWrite" />
                <entry key="dataAccess.name" value="data/accountExtract.csv" />
            </map>
        </property>
    </bean>

    <!-- IMPORT DATA INTO SALESFORCE -->
    <bean id="csvAccountImportProcess" class="com.salesforce.dataloader.process.ProcessRunner" scope="singleton">
        <description>csvAccountImport gets account info from CSV file and import it info into Salesforce org.</description>
        <property name="name" value="csvAccountImport" />
        <property name="configOverrideMap">
            <map>
                <entry key="sfdc.debugMessages" value="true" />
                <entry key="process.operation" value="insert" />
                <entry key="process.mappingFile" value="conf/accountImportMap.sdl" />
                <entry key="sfdc.entity" value="Account" />
                <entry key="dataAccess.type" value="csvRead" />
                <entry key="dataAccess.name" value="data/accountImport.csv" />
            </map>
        </property>
    </bean>

</beans>
./conf/accountExtractMap.sdl
# Account Extract Map
Id=Id
Name=Name
./conf/accountImportMap.sdl
# Account Import Map
Name=Name
./data/accountImport.csv
"NAME"
"Test Account 1"
"Test Account 2"
"Test Account 3"
"Test Account 4"
"Test Account 5"

Usage of dataloader CLI tool

  1. Run the sample account extract process. This command will generate ./data/accountImport.csv CSV file with the account info. It will override the existing file if it exists.
Terminal
./bin/process.sh csvAccountExtractProcess
  1. Run the sample account import process. This command will import the account info from ./data/accountImport.csv CSV file to Salesforce.
Terminal
./bin/process.sh csvAccountImportProcess

Credit goes to: @mhamzas