The Trailblazer Community in Slack is now in Open Beta—join and connect in real time. [Join us in Slack]
Specifies that for some fields, when a string is too large, the operation fails. Without the header, strings for these fields are truncated.
The AllowFieldTruncationHeader header affects the following datatypes:
In API versions previous to 15.0, if a value for one of the listed fields is too large, the value is truncated.
For API version 15.0 and later, if a value is too large, the operation fails and the fault code STRING_TOO_LONG is returned. AllowFieldTruncationHeader allows you to specify that the previous behavior, truncation, be used instead of the new behavior in API versions 15.0 and later.
This header has no effect in versions 14.0 and earlier.
convertLead(), create(), merge(), process(), undelete(), update(), and upsert()
Apex: executeanonymous()
Type: boolean
Description: If true, truncate field values that are too long, which is the behavior in API versions 14.0 and earlier. Default is false: no change in behavior. If a string or textarea value is too large, the operation fails and the fault code STRING_TOO_LONG is returned. The following list shows the field types affected by truncation and this header:
To create an account with a name that is too long for the Name field, use the AllowFieldTruncation header.
This sample:
AllowFieldTruncationHeader to true and retries the account creation, which succeeds.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}