欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

搞定Salesforce Data Loader命令行常见问题

最编程 2024-02-03 14:38:11
...

Data Loader是一个Salesforce提供的本地工具可以用来insert, upsert, update,导出和删除数据。

标准Data Loader使用向导需要我们手动操作这些命令。然而在很多的场景中,我们需要反复执行这些数据加载任务,例如每天晚上凌晨一点(夜间服务)来运行某些操作。因此,对于这些情况我们可以使用标准的Data Loader命令行工具来解决。

在本文中,我将会详细介绍如何使用Data Loader命令行

在Data loader中建立命令行的最重要的部分就是利用DataLoader提供的功能来生成加密密码。

Commandline Data Loader tools

这个目录包含两个应用程序批处理文件:“encrypt.bat“和“process.bat”

运行CMD,将命令行导航到“Program Files | Data Loader | bin”并运行命令。

encrypt.bat –g YOURSECRETKEY

Generate Secret Key for Command Line Dataloader

私有密钥是根据你输入的信息自动生成的。复制突出白色显示的文本并粘贴在新文本文件“Key.txt”。

现在再次运行上面的命令生成加密密码

encrypt.bat -e password "C:Users\shiva\Desktop\Data Loader Documents\Try\Key.txt"

Commandline Data Loader generate Encrypted Password

现在,注意这个密码,因为我们将用它来配置剩下的部分

用下面的命令确认密码是否正确:

encrypt.bat -v generatedPassword secretKey

如果您使用代理服务器,,可重复相同步骤生成加密的密码。

创建文件-“config.properties”:

这个文件包含所有常见的设置像用户名,加密的密码的等。这个文件也可以空白,不过最好将常见的配置都写在此文件里。Keys在这个文件将和结尾描述的“Process-config.xml”类似。下面是例子:

#Loader Config
#Wed Sep 19 2012
sfdc.debugMessages=true
process.encryptionKeyFile=C:\Users\shiva\Desktop\Data Loader Documents\Try\Key.txt
sfdc.debugMessagesFile = C:\Users\shiva\Desktop\Data Loader Documents\Try\AccountExport.log
sfdc.endpoint=https://login.salesforce.com
sfdc.username=ilovenagpur@gmail.com
sfdc.password=7b5693f0cad856dc778d4b8506f2c976
sfdc.proxyUsername=proxyUserName
sfdc.proxyPassword=encrypytesPassword
sfdc.proxyHost=proxyhostName
sfdc.proxyPort=123
sfdc.loadBatchSize=200
sfdc.timeoutSecs=600

创建文件-“process-conf.xml”

该文件包含导入导出的所有信息。在这里我们导入客户数据,所以该文件是:

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="Account"
    class="com.salesforce.dataloader.process.ProcessRunner"
    singleton="false">
        <description>Export Account Data</description>
        <property name="name" value="Account"/>
        <property name="configOverrideMap">
        <map>
            <entry key="sfdc.enableLastRunOutput" value="false"/>
            <entry key="sfdc.entity" value="Account"/>
            <entry key="process.operation" value="extract"/>
            <entry key="sfdc.extractionRequestSize" value="500"/>
            <entry key="sfdc.extractionSOQL" value="SELECT Id FROM Account"/>
            <entry key="dataAccess.name" value="D:Data LoadSeed DataNPower Production - 16 Aug 12AccountExport.csv"/>
            <entry key="dataAccess.type" value="csvWrite"/>
            <entry key="dataAccess.writeUTF8" value="true" />
        </map>
        </property>
    </bean>
</beans>

在本文的结尾,你可以看到所有参数的描述。假设我们在dataloader的Bin文件夹下运行下面的命令:

Process.bat "directory path where we have file process-config.xml"  process Name

在我们的例子中Process的名字是Account,Process名字只是属性名。

Run Commandline Data Loader

运行上面的命令后,你的数据将导出到开始配置的”process-config.xml”文件中。

在处理dataloader命令行的时候,有机会你会遇到一些错误。所以我也列出一些常见的错误和解决方案:

错误 1: Dataloader error: “javax.crypto.BadPaddingException:”Or error loading parameter of sfdc.password 解决方法: 将 “process.encryptionKeyFile=C:\Users\315447\Desktop\Data Loader\key.txt”要么放在 “config.properties” 文件中,要么放在 “process-conf.xml文件中”

<entry key="process.encryptionKeyFile" value="config/key.txt"/>

错误 2: 查询错误: query is empty 解决方法: Occurs, If “sfdc.extractionSOQL” key in beans node does not have valid SOQL.

Parameters for Process-config.xml:

Process-Config.xml的一些参数

PARAMETER

DESCRIPTION

<bean id=" PROCESSNAME " class="com.salesforce.lexiloader.process.ProcessRunner" singleton="false">

This first line uniquely defines the process in the XML file. This has to be unique and will be used to call the process later on. Only change the PROCESSNAMEand leave all other parts the same.

<description> Your Description here </description>

A description of the process.

<property name="name" value="PROCESSNAME "/>

Copy the PROCESSNAME and place it in this parameter. This is used in the log files when debug messages are showing. This is the name that is shown on the debug logs.

<property name="configOverrideMap">

These two lines initiate the parameters for the process. They should not be changed and should always be the same.

<entry key="sfdc.debugMessages" value="false"/>

Set this to True if you want detailed debug messages to appear in the command line.

<entry key="sfdc.debugMessagesFile" value="c:\\dataloader\\samples\\status\\accountMasterSoapTrace.log"/>

Set the value to a directory and a file to keep the detailed log file in. WARNING: This can create an extremely large file. Make sure that you have space on your hard drive before this is set.

<entry key="sfdc.endpoint" value="https://www.salesforce.com"/>

Keep default, unless loading into Sandbox. for sandbox, it is test.salesforce.com.

<entry key="sfdc.username" value="jitendrazaa@winter13Sand.com" />

Set this as the username of the user you are importing /exporting as.

<entry key="sfdc.password" value="b6b3016135f717754590a3e35b1db32b" /><br/> <entry key="process.encryptonKeyFile" value="C:\\Program Files\\salesforce.com\\Apex Data Loader 9.0\\test\\Key.txt" />

See this article on how to create Encrypted password for Command line Dataloader in Salesforce

<entry key="sfdc.timeoutSecs" value="600"/>

System time out value.

<entry key="sfdc.loadBatchSize" value="200"/>

System batch load size.

<entry key="process.operation" value="extract" />

Signifies the process being run.Possible Values:ExtractInsertDeleteUpsert

<entry key="sfdc.entity" value="Account"/>

Signifies the object that you are running this process for. This should be the API name of the object when you are running processes for custom objects.

<entry key="sfdc.extractionRequestSize" value="500"/>

Batch size for extract processes only

This is the SOQL query run for extract processes. You can use the Data Loader GUI to generate the SOQL statement and conditions and simply cut and paste into this entry key.

<entry key="dataAccess.type" value="csvWrite" />

Signifies the action when doing the process for Extract, Insert, Delete, Upsert. This key should be used in conjunction with the "process.operation" key.Possible Values:csvReadcsvWritedatabaseReaddatabaseWriteWhen using Extract processes, use csvWrite. When using Delete, Insert, and Upsert processes, use csvRead.

<entry key="dataAccess.writeUTF8" value="true" />

When using a "csvWrite" dataccess type, set this to True when you want files to be extracted as UTF-8.

<entry key="dataAccess.name" value="<b>C:\\Program Files\\salesforce.com\\Apex Data Loader 9.0\\test\\extract.csv</b>" />

Signifies the location and file name of the dataaccess type process. If running a csvRead, the process will look for the file in this location. If running a csvWrite, the process will replace the file in this location.

<entry key="process.mappingFile" value="<b>C:\\Program Files\\salesforce.com\\Apex Data Loader 9.0\\test\\upsert_mapping.sdl</b>"/>

Signifies the location of a data loader mapping file. This is the same mapping file used when saving a mapping from the data loader GUI. This is required for insert, delete and upsert processes.

<entry key="sfdc.externalIdField" value="Customer_ID__c"/>

Signifies the External ID field used for the upsert process. This is required for upserts.

<entry key="process.statusOutputDirectory" value="C:\\Program Files\\salesforce.com\\Apex Data Loader 9.0\\test\\logs\\" />

Signifies the directory where the data loader success and error files will be created in.

<entry key="process.outputSuccess" value="C:\\Program Files\\salesforce.com\\Apex Data Loader 9.0\\test\\Logs\\csvUpsertProcess_success.csv" /><br/><br/> <entry key="process.outputError" value="C:\\Program Files\\salesforce.com\\Apex Data Loader 9.0\\test\\Logs\\csvUpsertProcess_error.csv" />

Signifies the directory and filename where the success and error files will be created. If this key is not specified, the "process.statusOutputDirectory" key will contain similar filenames as ones generated by the data loader GUI.

  • Extract
  • Insert
  • Delete
  • Upsert

<entry key="sfdc.entity" value="Account"/>Signifies the object that you are running this process for. This should be the API name of the object when you are running processes for custom objects.<entry key="sfdc.extractionRequestSize" value="500"/>Batch size for extract processes only This is the SOQL query run for extract processes. You can use the Data Loader GUI to generate the SOQL statement and conditions and simply cut and paste into this entry key.<entry key="dataAccess.type" value="csvWrite" />Signifies the action when doing the process for Extract, Insert, Delete, Upsert. This key should be used in conjunction with the "process.operation" key. Possible Values:

  1. csvRead
  2. csvWrite
  3. databaseRead
  4. databaseWrite

When using Extract processes, use csvWrite. When using Delete, Insert, and Upsert processes, use csvRead.<entry key="dataAccess.writeUTF8" value="true" />When using a "csvWrite" dataccess type, set this to True when you want files to be extracted as UTF-8.<entry key="dataAccess.name" value="<b>C:\\Program Files\\salesforce.com\\Apex Data Loader 9.0\\test\\extract.csv</b>" />Signifies the location and file name of the dataaccess type process. If running a csvRead, the process will look for the file in this location. If running a csvWrite, the process will replace the file in this location.<entry key="process.mappingFile" value="<b>C:\\Program Files\\salesforce.com\\Apex Data Loader 9.0\\test\\upsert_mapping.sdl</b>"/>Signifies the location of a data loader mapping file. This is the same mapping file used when saving a mapping from the data loader GUI. This is required for insert, delete and upsert processes.<entry key="sfdc.externalIdField" value="Customer_ID__c"/>Signifies the External ID field used for the upsert process. This is required for upserts.<entry key="process.statusOutputDirectory" value="C:\\Program Files\\salesforce.com\\Apex Data Loader 9.0\\test\\logs\\" />Signifies the directory where the data loader success and error files will be created in.<entry key="process.outputSuccess" value="C:\\Program Files\\salesforce.com\\Apex Data Loader 9.0\\test\\Logs\\csvUpsertProcess_success.csv" /><br/><br/> <entry key="process.outputError" value="C:\\Program Files\\salesforce.com\\Apex Data Loader 9.0\\test\\Logs\\csvUpsertProcess_error.csv" />Signifies the directory and filename where the success and error files will be created. If this key is not specified, the "process.statusOutputDirectory" key will contain similar filenames as ones generated by the data loader GUI.