前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Salesforce的Data Loader命令行-解决常见错误

Salesforce的Data Loader命令行-解决常见错误

作者头像
臭豆腐
发布2019-04-16 17:06:18
1.5K0
发布2019-04-16 17:06:18
举报
文章被收录于专栏:CRM日记本CRM日记本

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”并运行命令。

代码语言:javascript
复制
encrypt.bat –g YOURSECRETKEY

Generate Secret Key for Command Line Dataloader

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

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

代码语言:javascript
复制
encrypt.bat -e password "C:Users\shiva\Desktop\Data Loader Documents\Try\Key.txt"

Commandline Data Loader generate Encrypted Password

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

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

代码语言:javascript
复制
encrypt.bat -v generatedPassword secretKey

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

创建文件-“config.properties”:

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

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

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

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

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

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

代码语言:javascript
复制
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文件中”

代码语言:javascript
复制
<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.

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2015-03-11,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 CRM日记本 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
数据库
云数据库为企业提供了完善的关系型数据库、非关系型数据库、分析型数据库和数据库生态工具。您可以通过产品选择和组合搭建,轻松实现高可靠、高可用性、高性能等数据库需求。云数据库服务也可大幅减少您的运维工作量,更专注于业务发展,让企业一站式享受数据上云及分布式架构的技术红利!
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档