Friday, June 1, 2012

Command Line DataLoader


Command Line Data Loader
   Data Loader is used to data upload or load for Salesforce.com. Now we can used Data Loader through command line means we can write our own SOQL and CSV file. For that we have written following steps:
  1. Create test folder: C:\Program Files\salesforce.com\Apex Data Loader 14.0\test
  2. It must contain process-conf.xml, log-conf.xml and key.txt.
  3. Above xml file can copy from config folder.
  4. Key file contains Password encrypted format.
·        Open cmd and go to C:\Program Files\salesforce.com\Apex Data Loader 14.0\bin
….\bin> encrypt.bat –g “Pwd”
·        Enter you will get encrypted password like
….\bin>sadsad2232ds3
·        Copy above password and past into Key.txt file.
….\bin> encrypt.bat –g Passsword “C:\Program Files\salesforce.com\Apex Data Loader 14.0\test\Key.txt”
        Above steps for Encrypted password

 5. Edit the process-conf.xml file and copy past the following code in Bean and Save.

<bean id="csvExtractAccountsProcess" class="com.salesforce.dataloader.process.ProcessRunner" singleton="false">
<description>Inserts artist names from CSV file into Artist custom object.</description>
 <property name="name" value="csvExtractAccounts"/>
 <property name="configOverrideMap">
 <map>
            <entry key="sfdc.debugMessages" value="false"/>
            <entry key="sfdc.debugMessagesFile" value="C:\Program Files\salesforce.com\Apex Data Loader 14.0\test\csvInsertArtist.log"/>
            <entry key="sfdc.endpoint" value="https://test.salesforce.com/"/>
            <entry key="sfdc.username" value="raees.sabir@accenture.com.prod.f4rtest"/>
            <entry key="sfdc.password" value="2570bebe6d904382"/>
            <entry key="process.encryptionKeyFile" value="C:\Program Files\salesforce.com\Apex Data Loader 14.0\test\Key.txt" />
            <entry key="sfdc.timeoutSecs" value="540"/>
            <entry key="sfdc.loadBatchSize" value="200"/>
            <entry key="sfdc.entity" value="Account"/>
            <entry key="process.operation" value="extract"/>
            <entry key="dataAccess.type" value="csvWrite" />  
            <entry key="dataAccess.writeUTF8" value="true" />
            <entry key="sfdc.extractionRequestSize" value="500"/>
            <entry key="sfdc.extractionSOQL" value="Select Id,Name FROM Account LIMIT 10" />
            <entry key="process.mappingFile" value="C:\Program Files\salesforce.com\Apex Data Loader 14.0\test\upsert_mapping.sdl"/>
            <entry key="process.statusOutputDirectory" value=":\Program Files\salesforce.com\Apex Data Loader 14.0\test\Logs\" />
            <entry key="process.outputSuccess" value="C:\Program Files\salesforce.com\Apex Data Loader 14.0\test\Logs\csvUpsertProcess_success.csv" />
            <entry key="process.outputError" value="C:\Program Files\salesforce.com\Apex Data Loader 14.0\test\Logs\csvUpsertProcess_error.csv" />
            <entry key="dataAccess.name" value="C:\Program Files\salesforce.com\Apex Data Loader 14.0\test\Accountextract.csv" />
   </map>
 </property>
</bean>

6. Run through command line:
../bin> process.bat  “c:\program files\salesforce.com\apex data loader 9.0\test\”  csvAccountExtractProcess

Note: To call different processes one after the other, create a batch file in the bin directory and prefixing each call with the “call” function. The image below shows how to call the csvAccountExtractProcess 3 times and clearing the screen after each run.

2 comments: