STRING_TOO_LONG: data value too large for field
What does this error mean?
This error occurs when a value being inserted or updated exceeds the maximum length allowed for a field in Salesforce.
For example, if a text field allows 80 characters and your code attempts to insert 120 characters, Salesforce throws the STRING_TOO_LONG error to prevent data overflow. [oai_citation:0‡Titan DXP Site](https://titandxp.com/kb/getting-started/string_too_long/?utm_source=chatgpt.com)
Common Causes
1. Text value exceeds field length
The most common cause is inserting text longer than the field’s maximum length.
2. Long API payloads
External integrations may send values longer than allowed by the Salesforce field configuration.
3. Concatenated strings in Apex
When combining multiple strings in Apex, the resulting value may exceed the field size.
4. Large email or rich text content
Rich text or HTML content inserted into text fields can exceed the field length limit.
How to Fix It
Solution 1 — Check field length
Navigate to:
Setup → Object Manager → Fields & Relationships
Solution 2 — Truncate the value in Apex
String value = longText;
if(value.length() > 80){
value = value.substring(0,80);
}
account.Description = value;
Solution 3 — Increase field length
If the data legitimately needs more space, increase the maximum field length or switch to a Long Text Area field.
Pro Tip: Always validate string length before performing DML operations when processing API integrations or large text values.