AllowFieldTruncationHeader

The AllowFieldTruncationHeader header specifies the truncation behavior of the following field datatypes that contain strings:

In API versions previous to 15.0, if you specify a value for a field that is one of the datatypes listed, and that value is too large, the value is truncated. For API version 15.0 and later, if a value is specified that 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.

API Calls

convertLead(), create(), merge(), process(), undelete(), update(), and upsert()

Apex: executeanonymous()

Fields

Element Name Type Description
allowFieldTruncation boolean 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:

  • anyType, if it represents one of the other datatypes in this list
  • email
  • encryptedstring
  • mulitpicklist
  • phone
  • picklist
  • string
  • textarea

Sample Code—Java

This sample shows how to turn field truncation on to allow the creation of an account with a name that is longer than the maximum field length. It creates an account sObject with a name that exceeds the field limit of 255 characters. It then attempts to make the create call, which fails because of the name field length. Next, it sets the AllowFieldTruncationHeader to true and retries the account creation, which succeeds.

public void allowFieldTruncationSample() {
  try {
    Account account = new Account();
    // Construct a string that is 256 characters long.
    // Account.Name's limit is 255 characters.
    String accName = "";
    for (int i = 0; i < 256; i++) {
      accName += "a";
    }
    account.setName(accName);
    // Construct an array of SObjects to hold the accounts.
    SObject[] sObjects = new SObject[1];
    sObjects[0] = account;
    // Attempt to create the account. It will fail in API version 15.0
    // and above because the account name is too long.
    SaveResult[] results = connection.create(sObjects);
    System.out.println("The call failed because: "
       + results[0].getErrors()[0].getMessage());
    // Now set the SOAP header to allow field truncation.
    connection.setAllowFieldTruncationHeader(true);
    // Attempt to create the account now.
    results = connection.create(sObjects);
    System.out.println("The call: " + results[0].isSuccess());
  } catch (ConnectionException ce) {
    ce.printStackTrace();
  }
}
© Copyright 2000–2014 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.