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

compileAndTest()

単一のコールで Apex をコンパイルおよびテストします。

構文

1CompileAndTestResult[] = compileAndTest(CompileAndTestRequest request);

使用方法

このコールを使用して、1 つのコールで指定した Apex にコンパイルとテストの両方を実行します。本番組織 (Developer Edition または Sandbox Edition ではない) は、compileClasses() または compileTriggers() の代わりにこのコールを使用する必要があります。

このコールは、DebuggingHeader と SessionHeader をサポートしています。API の SOAP ヘッダーについての詳細は、「SOAP API 開発者ガイド」を参照してください。

指定されたすべてのテストに合格する必要があります。合格しない場合、データはデータベースに保存されません。このコールが本番組織で呼び出されると、CompileAndTestRequestRunTestsRequest プロパティは無視され、組織で定義されたすべての単体テストが実行されます。これらのテストに合格する必要があります。

サンプルコード —Java

次の例では、checkOnlytrue に設定して、このクラスのコンパイルおよびテストを実行するが、クラスがデータベースに保存されないようにします。

1{
2    CompileAndTestRequest request;
3    CompileAndTestResult result = null;
4
5    String triggerBody = "trigger t1 on Account (before insert){ " +
6      "  for(Account a:Trigger.new){ " +
7      "   a.description = 't1_UPDATE';}" +
8      "}";
9
10    String testClassBody = "@isTest private class TestT1{" +
11      "    // Test for the trigger" +
12      "    public static testmethod void test1(){" +
13      "      Account a  = new Account(name='TEST');" +
14      "      insert(a);" +
15      "      a = [select id,description from Account where id=:a.id];" +
16      "      System.assert(a.description.contains('t1_UPDATE'));" +
17      "    }" +
18      "    // Test for the class" +
19      "    public static testmethod void test2(){" +
20      "      String s = C1.method1();" +
21      "      System.assert(s=='HELLO');" +
22      "    }" +
23      "}";
24
25    String classBody = "public class C1{" +
26      "    public static String s ='HELLO';" +
27      "    public static String method1(){" +
28      "      return(s);" +
29      "    }" +
30      "}";
31
32    request = new CompileAndTestRequest();
33
34    request.setClasses(new String[]{classBody, testClassBody});
35    request.setTriggers(new String[]{triggerBody});
36    request.setCheckOnly(true);
37
38    try {
39        result = apexBinding.compileAndTest(request);
40    } catch (RemoteException e) {
41        System.out.println("An unexpected error occurred: " + e.getMessage());
42    }
43    assert (result.isSuccess());
44}

引数

名前 説明
request CompileAndTestRequest Apex およびこの要求に設定する必要のある項目の値を含む要求。