我是靠谱客的博主 魁梧萝莉,最近开发中收集的这篇文章主要介绍【Salesforce工具篇】Ant Migration Tool Guide 从入门到深入,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

1、【下载安装与配置】:以Win10为例
先决条件
安装Ant Migration Tool前,Java和Ant必须被正确地安装和配置(推荐Java v1.8.x+,TLS1.2,Ant v1.10.x+,Ant Migration Tool v48.x+),可以用如下方法检查是否符合条件:
a. 打开cmd,并输入"java -version",如下:

b. 输入"ant -version",如下:

如果不符合条件,请参考【Salesforce工具篇】正确配置Data Loader环境下载Java JDK,并前往Apache Ant下载Ant。
下载好工具后请正确配置环境变量:

符合安装要求后,请遵循以下步骤下载并配置Ant Migration Tool
a. 下载 Spring '20 Ant Migration Tool
b. 将文件夹中的"ant-salesforce.jar"文件,复制粘贴进Apache Ant的lib文件夹里。

2、【使用Ant Migration Tool】:本节将使用工具提供的Sample数据作测试
a. 目标:我们将使用cmd对目标org作如下3类操作:检索,部署与删除;

b. 熟悉Ant Migration Tool的配置文件:以从A org拉代码,部署到B org为例

2021-01-22 纠正:上图#1与#2位置对调

#1. 首先我们配置A org的登录账密拉代码,然后配置B org的登录账密部署代码;

#2. 检索,部署与删除
检索:拉代码package.xml可使用通配符*

部署:部署代码package.xml不能使用通配符*

删除:删代码deployRoot保留2个文件[package.xml (只包含package和version节点,无types节点)与destructiveChanges.xml]

删除注意事项:
#1 假如package.xml与destructiveChanges.xml文件内容一致,且deployRoot中包含检索的metadata文件,情况会怎样?如下图:

上述情况,会先走destructiveChanges.xml,然后走package.xml,因此旧classes和labels被删除,新classes和labels被创建。

#2 当意图为删文件,而package.xml和destructiveChanges.xml内容一致,否则将出现下图错误:

这时,刚好走完删除,重新部署时因缺乏metadata源文件,导致整个过程失败(prod中classes和labels依旧如故)。

#3 运行多个指定测试类:

如果使用Change Set / HaoIDE / VS Code / Workbench部署代码时,运行指定测试类可以用逗号','隔开,但Ant配置文件需用runTest包裹每一项Test Class。

3、【相关笔记】:

testLevel: [NoTestRun, RunSpecifiedTests, RunLocalTests, RunAllTestsInOrg]

        Ref: Running a Subset of Tests in a Deployment
        NoTestRun — No tests are run, default for dev environments, such as sandbox, Developer Edition, or trial organizations.
        RunSpecifiedTests — Each class and trigger must be covered over 75%. It's different from the overall coverage percentage.
        RunLocalTests — All tests (exclusive tests for installed managed and unlocked packages) in your org are run, default for prod that include Apex classes or triggers.
        RunAllTestsInOrg — All tests (including tests of managed packages) are run. The tests include all tests in your org.

deployCode和undeployCode其在build.xml的配置类似,详细参数含义见Deploying Changes to a Salesforce Org
        #1 用账密登录或sessionId登录二选一,如果账密登录需要security token,可拼接至pwd后;
        #2 checkOnly - Set to true to perform a test deployment (validation) of components without saving the components in the target org.
        #3 purgeOnDelete - If true, the deleted components aren't stored in the Recycle Bin. Just works in DE or sandbox, not in prod.

Connection Problems

        Ref: Common Migration Issues
        Request timed out — When you retrieve or deploy metadata, the request is sent asynchronously, meaning that the response is not returned immediately. Because these calls are asynchronous, the server will process a deploy() to completion even if the Ant Migration Tool times out. If the deploy succeeds, the changes will be committed to the server. If the deploy fails after timing out, there is no way to retrieve the error message from the server. For this reason, it is important to tune your pollWaitMillis and maxPoll parameters if you receive time-out errors:

  • pollWaitMillis — The number of milliseconds to wait between polls for retrieve/deploy results. The default value is 10000 milliseconds (ten seconds). For long-running processes, increase this number to reduce the total number of polling requests, which count against your daily API limits. i.e. pollWaitMillis="40000"
  • maxPoll — The number of polling attempts to be performed before aborting. The default value is 200. When combined with the default value of pollWaitMillis (10000), this means the Ant Migration Tool will give the server process a total of 2,000 seconds (33 minutes) to complete before timing out. The total time is computed as 200 poll attempts, waiting 10 seconds between each.

4、【其他资料】:
QUICK WAY TO REMOVE APEX CLASS FROM A PRODUCTION ORG
Understanding deploy

最后

以上就是魁梧萝莉为你收集整理的【Salesforce工具篇】Ant Migration Tool Guide 从入门到深入的全部内容,希望文章能够帮你解决【Salesforce工具篇】Ant Migration Tool Guide 从入门到深入所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(47)

评论列表共有 0 条评论

立即
投稿
返回
顶部