How to create the data loader script for update/replace the record
Firstly download the dataloader for windows
- ApexDataLoader.exe
- Install this .exe file in windows
Create The Encrypted Key for the password encryption which is used in Process-conf.xml.
- Open a command prompt window by clicking Start | All Programs | Accessories | Command Prompt. Alternatively, you can click Start | Run, enter cmd in the Open field, and click OK
- In the command window, enter cd\ to navigate to the root directory of the drive where Data Loader is installed.
cd C:\Program Files (x86)\salesforce.com\Data Loader \bin
- Create an encryption key by entering the following command. Replace
with any string.
encrypt.bat - g <seedtext>
The generated Encrypted Key is b2b1826b573e294f
- This Key is save in .key file
Create The Encrypted Password for login the username
- In this step, you create the encrypted password using the key that you generated in the previous step.
- In the same command prompt window, enter the following command. Replace <password> with the password that Data Loader uses to log in to Salesforce. Replace
with the file path to the key.txt file that you created in the previous step.
encrypt.bat - e <password> "<filepath>\filename.key"
- This encrypted password is used in process-conf.xml file for login userpassword
Create the Field Mapping File
- The field mapping file associates data sources with destinations. This is a text file, typically with an .sdl file extension. for update/replace the record mapping file is the most important because record is updated with mapping file and all field have to map for update, Like
- #Mapping values
- Id=Id
- [Source Field Name]=[destination Field Name]
so the data source is on the left of the equals sign and the destination field is on the right.
Create Configuration File
- The process-conf.xml file contains the information that Data Loader needs to process the data. Each <bean> in the process-conf.xml file refers to a single process such as an insert, upsert, export,
and delete so on. This file ..\conf directory.
- Create bean for Extract the record for Update as per given below example
<bean id="csvBGCSOUSCrimDetailsextractProcess"
class="com.salesforce.dataloader.process.ProcessRunner"
singleton="false">
<description>csvBGCSOUSCrimDetailsextractProcess job gets account info from salesforce and saves info into a CSV file."</description>
<property name="name" value="BGCSOUSCrimDetailsextract"/>
<property name="configOverrideMap">
<map>
<entry key="sfdc.debugMessages" value="false"/>
<entry key="sfdc.debugMessagesFile"
value="D:\Data Loader\samples\status\sfdcSoapTrace.log"/>
<entry key="sfdc.endpoint" value="https://test.salesforce.com"/>
<entry key="sfdc.username" value="pre-employ-admin1@arcsdev.com"/>
<entry key="sfdc.password" value="8dff883fda7b0624de6aaaa2cbd54f7f"/>
<entry key="process.encryptionKeyFile"
value="D:\Data Loader\sample.key"/>
<entry key="sfdc.timeoutSecs" value="6000"/>
<entry key="sfdc.bulkApiCheckStatusInterval" value="5000"/>
<entry key="sfdc.bulkApiSerialMode" value="5000"/>
<entry key="sfdc.useBulkApi" value="true"/>
<entry key="sfdc.loadBatchSize" value="2000"/>
<entry key="sfdc.entity" value="BGC_SO_US_Crim_Details__c"/>
<entry key="sfdc.extractionRequestSize" value="500"/>
<entry key="sfdc.extractionSOQL" value="Select Id, SSN__c FROM BGC_SO_US_Crim_Details__c WHERE SSN__c != ''"/>
<entry key="process.operation" value="extract"/>
<entry key="process.mappingFile"
value="D:\Data Loader\samples\conf\BGCSOUSCrimDetailExtractMap.sdl"/>
<entry key="dataAccess.type" value="csvWrite"/>
<entry key="dataAccess.name" value="D:\Data Loader\bin\BGCSOUSCrimDetailsextract.csv"/>
</map>
</property>
</bean>
- Create bean for Update the record as per extract csv file, given below example
<bean id="csvBGCSOUSCrimDetailsUpdateProcess"
class="com.salesforce.dataloader.process.ProcessRunner"
singleton="false">
<description>csvBGCSOUSCrimDetailsUpdateProcess job gets account info from salesforce and saves info into a CSV file."</description>
<property name="name" value="BGCSOUSCrimDetailsUpdate"/>
<property name="configOverrideMap">
<map>
<entry key="sfdc.debugMessages" value="false"/>
<entry key="sfdc.debugMessagesFile"
value="D:\Data Loader\samples\status\sfdcSoapTrace.log"/>
<entry key="sfdc.endpoint" value="https://test.salesforce.com"/>
<entry key="sfdc.username" value="pre-employ-admin1@arcsdev.com"/>
<entry key="sfdc.password" value="8dff883fda7b0624de6aaaa2cbd54f7f"/>
<entry key="process.encryptionKeyFile"
value="D:\Data Loader\sample.key"/>
<entry key="sfdc.timeoutSecs" value="6000"/>
<entry key="sfdc.bulkApiCheckStatusInterval" value="5000"/>
<entry key="sfdc.bulkApiSerialMode" value="5000"/>
<entry key="sfdc.useBulkApi" value="true"/>
<entry key="sfdc.loadBatchSize" value="2000"/>
<entry key="sfdc.entity" value="BGC_SO_US_Crim_Details__c"/>
<entry key="sfdc.extractionRequestSize" value="500"/>
<entry key="process.operation" value="update"/>
<entry key="process.mappingFile" value="D:\Data Loader\samples\conf\BGCSOUSCrimDetailExtractMap.sdl"/>
<entry key="dataAccess.type" value="csvRead"/>
<entry key="dataAccess.name" value="D:\Data Loader\bin\BGCSOUSCrimDetailsUpdate.csv"/>
</map>
</property>
</bean>
For more information about the process configuration parameters, see Data Loader Process Configuration Parameters.
- sfdc.endpointbat - Enter the URL of the Salesforce instance for your organization; for example, https://test.salesforce.com.
- sfdc.usernamebat- Enter the username Data Loader uses to log in.
- sfdc.passwordbat - Enter the encrypted password value that you created above.
- process.mappingFilebat - Enter the path and file name of the mapping file.
- dataAccess.Namebat - Enter the path and file name of the data file that contains the accounts that you want to import.
- sfdc.debugMessagesbat - Currently set to true for troubleshooting. Set this to false after your import is up and running.
- sfdc.debugMessagesFilebat - 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.
- process.Operation - Enter the operation name which we want to perform.
- sfdc.entity - Enter the entity name on which perform the operation.
Create .csv File for store Extract data that is need to be updated.
- I have created .csv files for all process. This .csv file have to used for store the record.
Create Batch File for run multiple process in one time for each object.
- Create batch file for update as per given below example
@echo off
setlocal EnableDelayedExpansion
set filename=BGCSOUSCrimDetailsextract.csv
set num=123
set SSNnum=123456789
(
for /F "skip=1 tokens=1* delims=," %%A in (%filename%) do (
echo "%%~A","!SSNnum!"
set /a num=num+1
set /a SSNnum=SSNnum+1
)) > BGCSOUSCrimDetailsnewupdate.csv
echo "Id","SSN__c"> BGCSOUSCrimDetailsupdate.csv
type BGCSOUSCrimDetailsnewupdate.csv >> BGCSOUSCrimDetailsupdate.csv
del BGCSOUSCrimDetailsnewupdate.csv
- I have created the batch file for Update the record like UpdateAccountCSV.bat in ..\Data Loader\bin directory and set the batch file for update and filepath of process-conf.xml. Like
@setlocal enableextensions
@cd /d "%~dp0"
call process.bat "<full path of process-config.xml>" <processName>(for extract the record)
call [update record batch name].bat
call process.bat "<full path of process-config.xml>" <processName>(for update the record in SF)
- @setlocal enableextensions and @cd /d "%~dp0" used for current directory from system32 in batch file for run as Administrator.
Run "UpdateAllObjects.bat" batch file by run as Administrator for perform the extract/Update operationfor all objects
Notes :
- Data loader command line use Bulk API for Update/replace records.
- This Configuration is one time. After admin1 Sandbox Refresh no need to configure script again. Only Run "UpdateAllObjects.bat" batch file by run as Administrator on dev server 52.3.218.218 at the given location for replacing the sensitive data of main pre-employ objects records
- D:\Data Loader\bin
- success and failed of each object data replacement can be checked via the suucess/error log file at the given path:
- D:\Data Loader\bin\log
- There are around 36 batch files and some .csv data files on above location, we need to delete all the .csv files if exist and log folder files as those contains old data records and need to run the "UpdateAllObjects.bat" batch file which will run 18 batch files. For single object replacement we need to run the batch file which contains "SF.bat" as suffix for example we need to run UpdateAccountSF.bat file and not UpdateAccountCSV.bat as UpdateAccountCSV.bat is being called inside UpdateAccountSF.bat file
- SVN Repo Address : http://vsvn.arcscorp.net:3391/svn/arcs/arcsdev.com/preemploy/utilities/dataloadercliq/replace-script/Data Loader
Click here for delete