AllowFieldTruncationHeader
AllowFieldTruncationHeader ヘッダーは、次のデータ型に影響します。
- anyType (ここにリストされていないデータ型のいずれかを示す場合)
- encryptedstring
- multipicklist
- phone
- picklist
- string
- textarea
バージョン 15.0 より前の API では、記載のいずれかの項目の値が大きすぎる場合、値は切り捨てられます。
API バージョン 15.0 以降では、値が大きすぎると、操作は失敗し、失敗コード STRING_TOO_LONG が返されます。AllowFieldTruncationHeader ヘッダーを使用すると、API バージョン 15.0 以降の新しい動作ではなく、以前の動作である切り捨てを使用するように指定できます。
このヘッダーはバージョン 14.0 以前の製品には無効です。
API コール
convertLead()、create()、merge()、process()、undelete()、update()、および upsert()
Apex: executeanonymous()
項目
サンプルコード — Java
[名前] 項目の名前が長すぎる取引先を作成する場合、AllowFieldTruncation ヘッダーを使用します。
この例では、次のような作業を行います。
- 255 文字の項目制限を超える名前を使用して取引先オブジェクトを作成します。
- create コールを送信しますが、名前項目の長さが原因で失敗します。
- AllowFieldTruncationHeader を true に設定し、取引先の作成を再試行すると、今度は成功します。
1public void allowFieldTruncationSample() {
2 try {
3 Account account = new Account();
4 // Construct a string that is 256 characters long.
5 // Account.Name's limit is 255 characters.
6 String accName = "";
7 for (int i = 0; i < 256; i++) {
8 accName += "a";
9 }
10 account.setName(accName);
11 // Construct an array of SObjects to hold the accounts.
12 SObject[] sObjects = new SObject[1];
13 sObjects[0] = account;
14 // Attempt to create the account. It will fail in API version 15.0
15 // and above because the account name is too long.
16 SaveResult[] results = connection.create(sObjects);
17 System.out.println("The call failed because: "
18 + results[0].getErrors()[0].getMessage());
19 // Now set the SOAP header to allow field truncation.
20 connection.setAllowFieldTruncationHeader(true);
21 // Attempt to create the account now.
22 results = connection.create(sObjects);
23 System.out.println("The call: " + results[0].isSuccess());
24 } catch (ConnectionException ce) {
25 ce.printStackTrace();
26 }
27}