特殊时期,大家一定要保重身体。增强自身免疫力,一切都会过去,一起加油!!!

Ant移行ツールの使用(Ant Migration Tool)

Salesforce zchao 3429℃ 0评论

この前は、同じ組織の本番サンドボックスとサンドボックス間の設定と開発の変更は、変更セットを介してリリースできましたが、一部の権限やその他の設定は変更できません。たとえば、サンドボックスで新しいタブが作成され、変更セットを介してリリースされた場合、このタブはデフォルトで本番環境で非表示になり、リセットする必要があります。また、同じ組織(ORG)に限定されています。2つの異なる組織の場合、異なる企業が変更されたコンテンツ構造などを公開したいのですが、実はそのような要望もあります。次に、さまざまな組織間で公開されるメタデータ(Metadata)APIの変更を通じて、VS Code、Ant移行ツールなどの他のツールを使用して完了する必要があります。

      Ant Migration Toolは、ローカルディレクトリとSalesforce組織間でメタデータを移動できるJava / Antベースのコマンドラインユーティリティです。メタデータAPIには、組織の設定とカスタム情報(メタデータ)を管理するオブジェクトのセットと、これらのオブジェクトを操作するためのSOAP呼び出しが含まれています。メタデータAPIを使用して、設定をXMLメタデータファイルとして操作します。

ほぼすべての種類の設定は、Apexクラスなどのメタデータで表すことができ、メタデータでは次のように表されます:ApexClass、トリガー:ApexTrigger、カスタムプロジェクト:CustomField。

プロファイル(プロファイル)内のオブジェクトのアクセス許可:

<objectPermissions>
        <allowCreate>true</allowCreate>
        <allowDelete>true</allowDelete>
        <allowEdit>true</allowEdit>
        <allowRead>true</allowRead>
        <modifyAllRecords>true</modifyAllRecords>
        <object>Lead_History__c</object>
        <viewAllRecords>true</viewAllRecords>
    </objectPermissions>
などなど、SF環境での設定。
    純粋にVScodeを使用して、サンドボックス内の一部のデータ構造を別の無関係な組織環境に移動しました。これは、新しい環境には存在しないカスタムオブジェクトなどの例です。元の環境のオブジェクトのメタデータを取り出し、新しい環境のメタデータに入れてから、VScode SFDXコマンドを使用して直接リリースします。明らかに、オブジェクトは新しい環境に存在しないため、直接エラーが発生しました。 。ただし、このオブジェクトを事前に新しい環境で作成し、コマンドで再発行すると、正常に渡すことができますが、問題が発生します。オブジェクト間に依存関係が多い場合は、変更する必要があります。
    最近、同じ組織であろうとなかろうと、お互いにリリースできるAntツールにも触れました。今のところオブジェクトの問題を心配する必要はなく、再構築する必要もありません。基本的な設定を行う必要があり、コマンドラインから使用できます。
・JavaJDK(Java 1.7.x以降)
https://www.oracle.com/java/technologies/javase-downloads.html
・Apache Ant(最新)
https://ant.apache.org/bindownload.cgi
・Ant移行ツール(36.0以降)
https://developer.salesforce.com/docs/atlas.ja-jp.daas.meta/daas/forcemigrationtool_install.htm
次のシステム環境変数を追加する必要があります

JAVA_HOME

C:\Java\sdk-14.0.1

ANT_HOME

C:\apache-ant-1.10.9

PATH

C:\apache-ant-1.10.9\bin

 

ant-sf_49.0のディレクトリ構造を簡単に見てみましょう

sample

codepkg

mypkg

removecodepkg

retrieveOutput

retrieveUnpackaged

unpackaged

build.properties

build.xml

ant-salesforce.jar

Readme.html

ファイルの説明

build.properties:組織のユーザ名とパスワード、接続URL情報など

# build.properties
#

# Specify the login credentials for the desired Salesforce organization
sf.username = xxx
sf.password =xxxxxx
#sf.sessionId = <Insert your Salesforce session id here. Use this or username/password above. Cannot use both>
#sf.pkgName = <Insert comma separated package names to be retrieved>
#sf.zipFile = <Insert path of the zipfile to be retrieved>
#sf.metadataType = <Insert metadata type name for which listMetadata or bulkRetrieve operations are to be performed>

# Use 'https://login.salesforce.com' for production or developer edition (the default if not specified).
# Use 'https://test.salesforce.com for sandbox.
sf.serverurl = https://login.salesforce.com

sf.maxPoll = 20
# If your network requires an HTTP proxy, see http://ant.apache.org/manual/proxy.html for configuration.
#

build.xml:Antツールで実行できるコマンドは以下の通り

リリース:deploy
取得:retrieveUnpackaged
変更:deployUnpackaged
削除:undeployCode

以下の例です。

<project name="Sample usage of Salesforce Ant tasks" default="test" basedir="." xmlns:sf="antlib:com.salesforce"><project name="Sample usage of Salesforce Ant tasks" default="test" basedir="." xmlns:sf="antlib:com.salesforce">
<property file="build.properties"/>

<property environment="env"/>
<!-- Setting default value for username, password and session id properties to empty string          so unset values are treated as empty. Without this, ant expressions such as ${sf.username}         will be treated literally.    -->

<condition property="sf.username" value=""> <not> <isset property="sf.username"/> </not> </condition>

<condition property="sf.password" value=""> <not> <isset property="sf.password"/> </not> </condition>

<condition property="sf.sessionId" value=""> <not> <isset property="sf.sessionId"/> </not> </condition>

<taskdef resource="com/salesforce/antlib.xml" uri="antlib:com.salesforce">

<classpath>

<pathelement location="../ant-salesforce.jar" />

</classpath>

</taskdef>

 

<target name="deploy">

<sf:deploy username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" deployRoot="unpackaged" rollbackOnError="true"/>

</target>

</project>

 

package.xml:様々なメタデータのAPIで資源を取得と変更

<?xml version="1.0" encoding="UTF-8"?>

<?xml version="1.0" encoding="UTF-8"?>

<Package xmlns="http://soap.sforce.com/2006/04/metadata">

<types>

<members>*</members>

<name>ApexClass</name>

</types>

<types>

<members>*</members>

<name>ApexTrigger</name>

</types>

<types>

<members>*</members>

<name>Workflow</name>

</types>

<version>49.0</version>
</Package>

 

destructiveChanges.xml  : 削除するメタデータ型と資源

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>codepkg</fullName>
<types>
<members>SampleDeployClass</members>
<members>SampleFailingTestClass</members>
<name>ApexClass</name>
</types>
<types>
<members>SampleAccountTrigger</members>
<name>ApexTrigger</name>
</types>
<version>49.0</version>
</Package>

 

 

 

apache-ant-1.10.9のディレクトリ構造

bin

etc

lib

manual

 

Ant 移行ツールを動き為に、apache-ant-1.10.9\lib下のant-salesforce.jarをC:\ant-sf_49.0の下にコピーします。

C:\apache-ant-1.10.9\lib\ant-salesforce.jar

C:\ant-sf_49.0\ant-salesforce.jar

 

今は試してみましょう。

新しいオブジェクトを自分設定した組織にリリースしたいのですが、

メタデータファイルを準備しておきます。(VS Codeとかで)

メタデータ取得:こちら

VSCodeでSFDC環境構築、複数の方法でメタデータを取得ーVSCode(利用できるPackage.xmlをアップロード)

以下の配置です。

C:\ant-sf_49.0\sample\unpackaged

objects(オブジェクトの詳細定義)

package.xml

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>MyPkg</fullName>
<types>
<members>myobj__c</members>
<name>CustomObject</name>
</types>
<version>49.0</version>
</Package>

build.xml:

<target name=”deploy”>   

<sf:deploy username=”${sf.username}” password=”${sf.password}” sessionId=”${sf.sessionId}” serverurl=”${sf.serverurl}” maxPoll=”${sf.maxPoll}” deployRoot=”unpackaged” rollbackOnError=”true”/>

</target>

これから、コマンドで実行します。

 

win+r⇒cmd

ant deploy

(target name=”deploy”)と同じようにご注意くださいね。

実際の環境で確認できます。

直接リリースできました。

 

コマンド
データを取得の例
ant retrieveUnpackaged

<!-- Retrieve an unpackaged set of metadata from your org -->
<!-- The file unpackaged/package.xml lists what is to be retrieved -->
<target name="retrieveUnpackaged">
<mkdir dir="retrieveUnpackaged"/>
<!-- Retrieve the contents into another directory -->
<sf:retrieve username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" retrieveTarget="retrieveUnpackaged" unpackaged="unpackaged/package.xml"/>
</target>

 

データを変更の例
ant deployUnpackaged

<!-- Deploy the unpackaged set of metadata retrieved with retrieveUnpackaged and run tests in this organization's namespace only-->
<target name="deployUnpackaged">
<sf:deploy username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" deployRoot="retrieveUnpackaged" rollbackOnError="true"/>
</target>

 

データを削除の例
ant undeployCode

<!-- Shows removing code; only succeeds if done after deployCode -->
<target name="undeployCode">
<sf:deploy username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" deployRoot="removecodepkg"/>
</target>

 

詳しくはAnt移行ツールをインストールしてから、全部確認できます。上のURLをご参考まで。

 

以上となります。

 

ご参考になれば幸いです。

 

 

转载请注明:zchao博客之家 » Ant移行ツールの使用(Ant Migration Tool)

喜欢 (5)or分享 (0)

您必须 登录 才能发表评论!