Tuesday, 25 September 2012

Data Loader CLI

Data Loader CLI (Command Line Interpreter):
* For automating the batches and schedule them using windows "Task Scheduler".
* We can perform import as well as export.
Windows-7 Task Scheduler
* We can do all the same things from the command line - insert data, update data, upsert data, delete data or extract data.
* Instead of "export", we should use "extract".
* We can move data to and from a comma-separated variable file (.csv) or to and from a relational database, such as Oracle or SQL Server, that has a standard JDBC driver.
* With a default installation on a Windows machine, all the Data Loader files will be placed in the Program Files\salesforce.com\Apex Data Loader APIversion directory, where APIversion corresponds to the API version.
* The process command, encrypt command will be in the bin subdirectory, and the configuration files will normally be in the conf subdirectory.
*The main configuration file used by the CLI is the process-conf.xml file.
* The process-conf.xml file contains a description for every potential process that could be called from the command line.
* Each of these processes is referred to as a Process Bean. 
* In this simple example, there is only one Process Bean in the process-conf.xml file.
* In normal practice, though, you would have a number of Process Bean sections in the configuration file, so calling out the specific process would make sense.
* The process-conf.xml file consists of a set of property-value pairs.
* The file used for this sample process is shown below, with an explanation of the key entries following the listing.
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <bean id="csvInsertArtist"
        <description>Inserts artist names from CSV file into Artist custom object.</description>
        <property name="name" value="csvInsertArtist"/>
        <property name="configOverrideMap">
                <entry key="sfdc.debugMessages" value="false"/>
                <entry key="sfdc.debugMessagesFile" value="c:\dataloader\csvInsertArtist.log"/>
                <entry key="sfdc.endpoint" value="https://www.salesforce.com"/>
                <entry key="sfdc.username" value="<i>Your Salesforce ID</i>"/>
                <entry key="sfdc.password" value="<i>Your encrypted Salesforce password</>"/>
                <entry key="sfdc.timeoutSecs" value="540"/>
                <entry key="sfdc.loadBatchSize" value="200"/>
                <entry key="sfdc.entity" value="Artist__c"/>
                <entry key="process.operation" value="insert"/>
                <entry key="process.mappingFile" value="c:\dataloader\artistmap.sdl"/>
                <entry key="process.outputError" value="c:\dataloader\errorInsertArtist.csv"/>
                <entry key="process.outputSuccess" value="c:\dataloader\successInsertArtist.csv"/>
                <entry key="dataAccess.name" value="c:\dataloader\Artists_1_100.csv" /> 
                <entry key="dataAccess.type" value="csvRead" /> 
                <entry key="process.initialLastRunDate" value="2007-06-06T00:00:00.000-0800"/>
 Configuration properties:
The process-conf.xml file contains properties for one or more Process Beans. Some of the more important properties are
  • name - used to identify the bean in the config.properties file and when you call it from the CLI
  • sfdc.entity - the Salesforce object that is the target of the actions. The value of this property is case sensitive.
  • process.operation - identifies the type of operation
  • process.mappingFile - identifies the mapping between the fields in the source file (dataAccess.name) and the Salesforce object. This mapping file is a .sdl file. The mapping file is the same format as the .sdl file created by the GUI when you save a mapping scheme.
  • dataAccess.type - identifies the operation to perform on the source file
  • sfdc.username - your Salesforce.com user name 
* To schedule the file we should open windows Task Scheduler.
C:\Program Files (x86)
C:\Program Files (x86)\salesforce.com\Data Loader\bin
process ../conf csvInsertArtist

* C:\Program Files (x86)
C:\Program Files (x86)\salesforce.com\Data Loader\bin
process ../conf csvInsertArtist
-- Save it as filename.bat--
Data Loader CLI

No comments:

Post a Comment