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

AllOrNoneHeader

コールで一部のレコードがエラーになった場合、すべてのメタデータ変更をロールバックするかどうかを示します。

バージョン

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

サポートされているコール

使用方法

デフォルトでは、このヘッダーが API バージョン 34.0 以降で使用されていない場合、コールで一部のレコードを保存できます (AllOrNoneHeader=false に相当)。正常に処理されたレコードは保存され、エラーのあったレコードは保存されません。

項目

項目名 説明
allOrNone boolean true に設定すると、コールのいずれかのレコードでエラーが発生した場合にすべてのメタデータの変更がロールバックされます。false に設定すると、コールの他のレコードでエラーが発生した場合に正常に処理されたレコードのみを保存できます。

サンプルコード —Java

次のようにコールを実行する前に AllOrNoneHeader をメタデータ接続に追加します。

1metadataConnection.setAllOrNoneHeader(true);

次の例では、2 つのカスタムオブジェクトを作成するときに AllOrNoneHeader を使用する方法を示します。2 番目のカスタムオブジェクトに必須の Name 項目がないため、create() コールでこのカスタムオブジェクトを作成できず、最初のカスタムオブジェクトがロールバックされます。このコードサンプルの後に出力が記載されています。

1import com.sforce.soap.metadata.*;
2import com.sforce.soap.metadata.Error;
3import com.sforce.ws.ConnectionException;
4
5public class CallWithHeader {
6	
7    MetadataConnection metadataConnection = null;
8    
9    public static void main(String[] args) throws ConnectionException {
10    	CallWithHeader samples = new CallWithHeader();
11        samples.createWithHeader();
12    }
13
14    public CallWithHeader() throws ConnectionException {
15        metadataConnection = MetadataLoginUtil.login();
16    }
17    
18    public void createWithHeader() throws ConnectionException {
19        // Define two custom objects to be inserted.
20        CustomObject co1 = new CustomObject();
21        String name1 = "MyCustomObject1";
22        co1.setFullName(name1 + "__c");
23        co1.setDeploymentStatus(DeploymentStatus.Deployed);
24        co1.setDescription("Created by the Metadata API");
25        co1.setEnableActivities(true);
26        co1.setLabel(name1 + " Object");
27        co1.setPluralLabel(co1.getLabel() + "s");
28        co1.setSharingModel(SharingModel.ReadWrite);
29
30        CustomField nf = new CustomField();
31        nf.setType(FieldType.Text);
32        nf.setLabel(co1.getFullName() + " Name");
33        co1.setNameField(nf);
34        
35        // The second custom object doesn't have a Name field
36        CustomObject co2 = new CustomObject();
37        String name2 = "MyCustomObject2";
38        co2.setFullName(name2 + "__c");
39        co2.setDeploymentStatus(DeploymentStatus.Deployed);
40        co2.setDescription("Created by the Metadata API");
41        co2.setEnableActivities(true);
42        co2.setLabel(name2 + " Object");
43        co2.setPluralLabel(co2.getLabel() + "s");
44        co2.setSharingModel(SharingModel.ReadWrite);
45
46        
47        // Setting the allOrNone header to true to cause
48        //  the call to not commit any record if one or more 
49        //  records in this call have failures.
50        metadataConnection.setAllOrNoneHeader(true);
51
52        // Now that the header has been set, make the create call.
53        SaveResult[] results = metadataConnection
54                .createMetadata(new Metadata[] { co1, co2 });
55
56        // Iterate through the call results
57        for (SaveResult r : results) {
58            if (r.isSuccess()) {
59                System.out.println("Created component: " + r.getFullName());
60            } else {
61                System.out
62                        .println("Errors were encountered while creating "
63                                + r.getFullName());
64                for (Error e : r.getErrors()) {
65                    System.out.println("Error message: " + e.getMessage());
66                    System.out.println("Status code: " + e.getStatusCode());
67                }
68            }
69        }
70    }
71
72}

これはサンプルで返される出力です。最初のレコードはロールバックされ、2 番目のレコードはエラーになっています。

1Errors were encountered while creating MyCustomObject1__c
2Error message: Record rolled back because not all records were valid and the request was using AllOrNone header
3Status code: ALL_OR_NONE_OPERATION_ROLLED_BACK
4Errors were encountered while creating MyCustomObject2__c
5Error message: Must specify a nameField of type Text or AutoNumber
6Status code: FIELD_INTEGRITY_EXCEPTION