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.
convertLead(), create(), merge(), process(), undelete(), update(), and upsert()
Apex: executeanonymous()
| 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:
|
public void allowFieldTruncationSample() throws InvalidSObjectFault,
InvalidFieldFault, InvalidIdFault, UnexpectedErrorFault, RemoteException {
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 15.0 and above because
// the account name is too long.
SaveResult[] results = binding.create(sObjects);
System.out.println("The call failed because: "
+ results[0].getErrors(0).getMessage());
// now set the SOAP header to allow field truncation
_AllowFieldTruncationHeader afth = new _AllowFieldTruncationHeader();
afth.setAllowFieldTruncation(true);
binding.setHeader(new SforceServiceLocator().getServiceName().getNamespaceURI(),
"AllowFieldTruncationHeader", afth);
// attempt to create the account now.
results = binding.create(sObjects);
System.out.println("The call: " + results[0].isSuccess());
}