この文章は Salesforce 機械翻訳システムを使用して翻訳されました。詳細はこちらをご参照ください。
英語に切り替える

deploy()

ファイル表現のコンポーネントを使用して、Salesforce 組織のファイル表現のコンポーネントを作成、更新、または削除します。

構文

1AsyncResult = metadatabinding.deploy(base64 zipFile, DeployOptions deployOptions)

使用方法

このコールを使用して、ファイル表現のコンポーネントを取得し、ファイル表現のコンポーネントが表すコンポーネントを作成、更新、または削除することにより、組織にファイル表現のコンポーネントをリリースします。

一度に最大 10,000 ファイルをリリースまたは取得でき、リリースまたは取得する .zip ファイルの最大サイズは 39 MB です。次の点に注意してください。

  • Force.com 移行ツールを使用して、展開したフォルダをリリースする場合、まずフォルダ内のすべてのファイルが圧縮されます。展開したフォルダ内の非圧縮コンポーネントの最大サイズは、圧縮率に応じて 400 MB 以下です。ファイルの圧縮率が高い場合、圧縮されたサイズは 39 MB を下回るため、合計およそ 400 MB ��移行できます。ただし、バイナリ静的リソースのように、それほど圧縮できないコンポーネントの場合、移行できるのは 400 MB 未満です。
  • メタデータ API base-64 では、コンポーネントを圧縮後にエンコードします。生成される .zip ファイルが SOAP メッセージの上限の 50 MB を超えることはできません。Base-64 エンコードではペイロードのサイズが増加するため、エンコードする前に、圧縮済みペイロードが約 39 MB を超えることはできません。

メモ

API バージョン 29.0 では、Salesforce は、リリース状況プロパティを改善し、deploy() コール後にリリースに関する情報を取得するために checkStatus() を使用する要件を削除しました。Salesforce では、API バージョン 28.0 以前で deploy() を使用する場合の checkStatus() の使用を引き続きサポートします。

API バージョン 29.0 以降の場合、次の手順に従って、パッケージ化されたコンポーネントまたはパッケージ化されていないコンポーネントをリリース (作成または更新) します。

  1. deploy() コールを発行して、非同期リリースを開始すると、AsyncResult オブジェクトが返されます。id 項目の値をメモし、次のステップで使用します。
  2. checkDeployStatus() コールの発行を、返される DeployResultdone 項目がコールの完了を示す true になるまでループします。DeployResult オブジェクトには、deploy() コールを使用して開始された進行中または完了済みのリリースに関する情報が含まれます。checkDeployStatus() をコールするとき、最初のステップの AsyncResult オブジェクトから id 値を渡します。

API バージョン 28.0 以前の場合、次の手順に従って、パッケージ化されたコンポーネントまたはパッケージ化されていないコンポーネントをリリース (作成または更新) します。

  1. deploy() コールを発行して、非同期リリースを開始すると、AsyncResult オブジェクトが返されます。コールが完了すると、done 項目に true が含まれます。ほとんどの場合、コールはすぐに完了しないため最初の結果に記述されません。完了している場合、返された id 項目の値を書き留め、次のステップを省略します。
  2. コールが完了していない場合、前のステップで deploy() コールから返された AsyncResult オブジェクトの id 項目の値を使用して、ループで checkStatus() コールを発行します。done 項目に true が含まれるまで、返される AsyncResult オブジェクトを確認します。deploy() コールを完了するまでにかかる時間は、リリースされる zip ファイルのサイズによって異なるため、zip ファイルのサイズが大きくなるほど、反復間の待機時間をより長くする必要があります。
  3. 最初のステップで返された id 値を使用して、checkDeployStatus() コールを発行し、deploy() コールの結果を取得します。

処理中または過去 30 日間で完了したリリースの状況を追跡するには、[設定] から [クイック検索] ボックスに「リリース状況」と入力し、[リリース状況] を選択します。

進行中またはキュー内のリリースは、リリースの横にある [キャンセル] をクリックしてキャンセルできます。リリースが完全にキャンセルされるまで、リリースの状況は Cancel Requested になります。キャンセルされたリリースは、[失敗] セクションにリストされます。

package.xml ファイルは、取得またはリリースするすべてのコンポーネントをリストするプロジェクトマニフェストです。package.xml を使用して、コンポーネントを追加できます。コンポーネントを削除するには、別のマニフェストファイルを追加します。「組織からのコンポーネントの削除」を参照してください。

権限

クライアントアプリケーションは、「すべてのデータの編集」権限でログインしている必要があります。

引数

名前 説明
zipFile base64 Base 64 で符号化されたバイナリデータクライアントアプリケーションは、バイナリデータを base64 に符号化する必要があります。
deployOptions DeployOptions リリースするパッケージまたはファイルを特定するためのオプションをカプセル化します。

DeployOptions

このコールでは次のリリースオプションを選択できます。

名前 説明
allowMissingFiles boolean package.xml に指定されているファイルが .zip ファイル内に存在しない場合、リリースを継続するかどうかを指定します。

本番組織へのリリースでは、この引数を設定することはできません。

autoUpdatePackage boolean ファイルが .zip ファイルにはあるが、package.xml で指定されていない場合、ファイルを自動的にパッケージに追加するかどうかを指定します。.zip ファイルを含む package.xml が更新された場合は、retrieve() が発行されます。

本番組織へのリリースでは、この引数を設定することはできません。

checkOnly boolean デフォルトは false です。コンポーネントを対象組織に保存せずにコンポーネントのテストリリース (検証) を実行するには、true に設定します。検証では、リリースで生成されるテストの結果を確認できますが、変更はコミットされません。テストに合格して検証が完了したら、テストを再実行することなくリリースできます。「deployRecentValidation()」を参照してください。
ignoreWarnings boolean 警告を無視してリリースの正常な完了を許可するか (true)、否か (false) を示します。デフォルトは false です。

警告の DeployMessage オブジェクトには次の値が含まれます。

  • problemTypeWarning
  • problem — 警告のテキスト

警告が発生し、ignoreWarningstrue に設定されている場合は、DeployMessagesuccess 項目は true です。ignoreWarningsfalse に設定されている場合、successfalse に設定され、警告はエラーとして処理されます。

この項目は API バージョン 18.0 以降で使用できます。バージョン 18.0 より前では、警告とエラーは区別されていませんでした。すべての問題はエラーとして処理され、リリースの成功を妨げていました。

performRetrieve boolean retrieve() コールをリリース直後に実行するか (true)、否か (false) を示します。リリース直後のものをすべて取得するには true に設定します。
purgeOnDelete boolean true の場合、destructiveChanges.xml マニフェストファイルの削除されたコンポーネントはごみ箱に保存されません。代わりに、即座に削除の対象となります。

この項目は API バージョン 22.0 以降で使用できます。

このオプションは Developer Edition 組織または Sandbox 組織でのみ機能しますが、本番組織では機能しません。

rollbackOnError boolean エラーが発生した場合、ロールバックを完了するか (true)、否か (false) を示します。false の場合、エラーなしで実行できるアクションはすべて実行され、残りのアクションではエラーが返されます。本番組織にリリースする場合は、このパラメータは true に設定されている必要があります。デフォルトは false です。
runAllTests boolean (廃止。API バージョン 33.0 以前でのみ使用可能)この項目のデフォルトは false です。インストール済みの管理パッケージから作成されたテストを含むすべての Apex テストをリリース後に実行するには、true に設定します。

リリースの一環として実行される Apex テストは、常に順序に従って同期実行されます。

メモ

runTests string[] リリース時に実行される Apex テストのリスト。クラス名 (1 インスタンスあたり 1 つの名前) を指定します。また、クラス名にはドット表記で名前空間を指定することもできます。詳細は、「リリースでのテストのサブセットの実行」 を参照してください。

このオプションを使用するには、testLevelRunSpecifiedTests に設定します。

singlePackage boolean 指定された .zip ファイルが指し示すディレクトリ構造が 1 つのパッケージを持つか (true)、パッケージのセットを持つか (false)) を示します。
testLevel TestLevel (string 型の列挙) 省略可能。リリースの一環として実行するテストを指定します。テストレベルは、リリースパッケージに存在するコンポーネントの種類に関係なく強制適用されます。有効な値は、次のとおりです。
  • NoTestRun — テストは実行されません。このテストレベルは、Sandbox、Developer Edition、トライアル組織など、開発環境へのリリースにのみ適用されます。このテストレベルは、開発環境のデフォルトです。
  • RunSpecifiedTestsrunTests オプションで指定したテストのみが実行されます。このテストレベルを使用する場合、コードカバー率要件がデフォルトのカバー率要件とは異なります。リリースパッケージ内にある各クラスおよびトリガは、実行されたテストによって 75% 以上のコードカバー率でカバーされる必要があります。このカバー率は、クラスおよびトリガごとに個別に計算され、全体のカバー率とは異なります。
  • RunLocalTestsインストール済みの管理パッケージから発生したテストを除き、組織のすべてのテストが実行されます。このテストレベルは、デフォルトでは Apex クラスまたはトリガを含む、本番リリース用です。
  • RunAllTestsInOrgすべてのテストが実行されます。テストには、管理パッケージのテストを含む、組織内のすべてのテストが含まれます。

テストレベルを指定しないと、デフォルトのテスト実行動作が使用されます。「リリースでのテストの実行」を参照してください。

リリースの一環として実行される Apex テストは、常に順序に従って同期実行されます。

メモ

この項目は、API バージョン 34.0 以降で使用できます。

応答

AsyncResult

サンプルコード —Java

このサンプルでは、zip ファイルでコンポーネントをリリースする方法を示します。zip ファイルの取得方法についての詳細は、retrieve() のサンプルコードを参照してください。

1package com.doc.samples;
2
3import java.io.*;
4
5import java.rmi.RemoteException;
6
7import com.sforce.soap.metadata.AsyncResult;
8import com.sforce.soap.metadata.DeployDetails;
9import com.sforce.soap.metadata.MetadataConnection;
10import com.sforce.soap.metadata.DeployOptions;
11import com.sforce.soap.metadata.DeployResult;
12import com.sforce.soap.metadata.DeployMessage;
13import com.sforce.soap.metadata.RunTestsResult;
14import com.sforce.soap.metadata.RunTestFailure;
15import com.sforce.soap.metadata.CodeCoverageWarning;
16import com.sforce.soap.enterprise.LoginResult;
17import com.sforce.soap.enterprise.EnterpriseConnection;
18import com.sforce.ws.ConnectionException;
19import com.sforce.ws.ConnectorConfig;
20
21/**
22 * Deploy a zip file of metadata components. 
23 * Prerequisite: Have a deploy.zip file that includes a package.xml manifest file that 
24 * details the contents of the zip file.
25 */
26public class DeploySample {
27    // binding for the metadata WSDL used for making metadata API calls
28    private MetadataConnection metadataConnection;
29
30    static BufferedReader rdr = new BufferedReader(new InputStreamReader(System.in));
31
32    private static final String ZIP_FILE = "deploy.zip";
33
34    // one second in milliseconds
35    private static final long ONE_SECOND = 1000;
36    // maximum number of attempts to deploy the zip file
37    private static final int MAX_NUM_POLL_REQUESTS = 50; 
38
39    public static void main(String[] args) throws Exception {
40        final String USERNAME = "user@company.com";
41        // This is only a sample. Hard coding passwords in source files is a bad practice.
42        final String PASSWORD = "password"; 
43        final String URL = "https://login.salesforce.com/services/Soap/c/29.0";
44        
45        DeploySample sample = new DeploySample(USERNAME, PASSWORD, URL);
46        sample.deployZip();
47    }
48    
49    public DeploySample(String username, String password, String loginUrl) 
50            throws ConnectionException {
51        createMetadataConnection(username, password, loginUrl);
52    }
53
54    public void deployZip()
55        throws RemoteException, Exception
56    {
57        byte zipBytes[] = readZipFile();
58        DeployOptions deployOptions = new DeployOptions();
59        deployOptions.setPerformRetrieve(false);
60        deployOptions.setRollbackOnError(true);
61        AsyncResult asyncResult = metadataConnection.deploy(zipBytes, deployOptions);
62        String asyncResultId = asyncResult.getId();
63        
64        // Wait for the deploy to complete
65        int poll = 0;
66        long waitTimeMilliSecs = ONE_SECOND;
67        DeployResult deployResult = null;
68        boolean fetchDetails;
69        do {
70            Thread.sleep(waitTimeMilliSecs);
71            // double the wait time for the next iteration
72            waitTimeMilliSecs *= 2;
73            if (poll++ > MAX_NUM_POLL_REQUESTS) {
74                throw new Exception("Request timed out. If this is a large set " +
75                        "of metadata components, check that the time allowed by " +
76                        "MAX_NUM_POLL_REQUESTS is sufficient.");
77            }
78            
79            // Fetch in-progress details once for every 3 polls
80            fetchDetails = (poll % 3 == 0);
81            deployResult = metadataConnection.checkDeployStatus(asyncResultId, fetchDetails);
82            System.out.println("Status is: " + deployResult.getStatus());
83            if (!deployResult.isDone() && fetchDetails) {
84                printErrors(deployResult, "Failures for deployment in progress:\n");
85            }
86        }
87        while (!deployResult.isDone());
88        
89        if (!deployResult.isSuccess() && deployResult.getErrorStatusCode() != null) {
90            throw new Exception(deployResult.getErrorStatusCode() + " msg: " +
91                    deployResult.getErrorMessage());
92        }
93
94        if (!fetchDetails) {
95            // Get the final result with details if we didn't do it in the last attempt.
96            deployResult = metadataConnection.checkDeployStatus(asyncResultId, true);
97        }
98
99        if (!deployResult.isSuccess()) {
100            printErrors(deployResult, "Final list of failures:\n");
101            throw new Exception("The files were not successfully deployed");
102        }
103        
104        System.out.println("The file " + ZIP_FILE + " was successfully deployed");
105    }
106    
107    /**
108     * Read the zip file contents into a byte array.
109     * @return byte[]
110     * @throws Exception - if cannot find the zip file to deploy
111     */
112    private byte[] readZipFile()
113        throws Exception
114    {
115        // We assume here that you have a deploy.zip file.
116        // See the retrieve sample for how to retrieve a zip file.
117        File deployZip = new File(ZIP_FILE);
118        if (!deployZip.exists() || !deployZip.isFile())
119            throw new Exception("Cannot find the zip file to deploy. Looking for " +
120                    deployZip.getAbsolutePath());
121        
122        FileInputStream fos = new FileInputStream(deployZip);
123        ByteArrayOutputStream bos = new ByteArrayOutputStream();
124        int readbyte = -1;
125        while ((readbyte = fos.read()) != -1)  {
126            bos.write(readbyte);
127        }
128        fos.close();
129        bos.close();
130        return bos.toByteArray();
131    }
132    
133 
134    /**
135     * Print out any errors, if any, related to the deploy.
136     * @param result - DeployResult
137     */
138    private void printErrors(DeployResult result, String messageHeader)
139    {
140        DeployDetails deployDetails = result.getDetails();
141        
142        StringBuilder errorMessageBuilder = new StringBuilder();
143        if (deployDetails != null) {
144            DeployMessage[] componentFailures = deployDetails.getComponentFailures();
145            for (DeployMessage message : componentFailures) {
146                String loc = (message.getLineNumber() == 0 ? "" :
147                    ("(" + message.getLineNumber() + "," +
148                            message.getColumnNumber() + ")"));
149                if (loc.length() == 0
150                        && !message.getFileName().equals(message.getFullName())) {
151                    loc = "(" + message.getFullName() + ")";
152                }
153                errorMessageBuilder.append(message.getFileName() + loc + ":" +
154                        message.getProblem()).append('\n');
155            }
156            RunTestsResult rtr = deployDetails.getRunTestResult();
157            if (rtr.getFailures() != null) {
158                for (RunTestFailure failure : rtr.getFailures()) {
159                    String n = (failure.getNamespace() == null ? "" :
160                        (failure.getNamespace() + ".")) + failure.getName();
161                    errorMessageBuilder.append("Test failure, method: " + n + "." +
162                            failure.getMethodName() + " -- " +
163                            failure.getMessage() + " stack " +
164                            failure.getStackTrace() + "\n\n");
165                }
166            }
167            if (rtr.getCodeCoverageWarnings() != null) {
168                for (CodeCoverageWarning ccw : rtr.getCodeCoverageWarnings()) {
169                    errorMessageBuilder.append("Code coverage issue");
170                    if (ccw.getName() != null) {
171                        String n = (ccw.getNamespace() == null ? "" :
172                            (ccw.getNamespace() + ".")) + ccw.getName();
173                        errorMessageBuilder.append(", class: " + n);
174                    }
175                    errorMessageBuilder.append(" -- " + ccw.getMessage() + "\n");
176                }
177            }
178        }
179        
180        if (errorMessageBuilder.length() > 0) {
181            errorMessageBuilder.insert(0, messageHeader);
182            System.out.println(errorMessageBuilder.toString());
183        }
184    }
185    
186    private void createMetadataConnection( 
187        final String username,
188        final String password,
189        final String loginUrl) throws ConnectionException {
190
191        final ConnectorConfig loginConfig = new ConnectorConfig();
192        loginConfig.setAuthEndpoint(loginUrl);
193        loginConfig.setServiceEndpoint(loginUrl);
194        loginConfig.setManualLogin(true);
195        LoginResult loginResult = (new EnterpriseConnection(loginConfig)).login(
196                username, password);
197        
198        final ConnectorConfig metadataConfig = new ConnectorConfig();
199        metadataConfig.setServiceEndpoint(loginResult.getMetadataServerUrl());
200        metadataConfig.setSessionId(loginResult.getSessionId());
201        this.metadataConnection = new MetadataConnection(metadataConfig);
202    }
203
204}