When inserting text into Salesforce multi-line text or rich text fields via the SOAP API, REST API, or Bulk API, you may receive a STRING_TOO_LONG error even when the text appears to be within the documented character limit. For example, attempting to insert exactly 4,000 characters into the CaseComment.Body field can result in a STRING_TOO_LONG error. This occurs because Salesforce enforces the character limit at the byte level for certain field types, and HTML-encoded characters or image source tags count against the limit in addition to visible characters.
To understand why the STRING_TOO_LONG error occurs and how to work within Salesforce field limits, it is important to distinguish between multi-line text and rich text field types.
Fields like CaseComment.Body have a documented limit of 4,000 bytes. However, the actual character limit can be less than 4,000, and varies depending on the character encoding used. The 4,000-character limit includes not just visible characters, but also any HTML encoding. For example, a single & HTML entity counts as 5 bytes but represents only 1 visible character.
The length limit in multi-line text fields is by default enforced at the character level in the Salesforce UI but at the byte level when inserting data via API. This discrepancy is the most common cause of the STRING_TOO_LONG error when inserting content that appears within limits.
Rich text fields that contain images include the full image source tag (<img src="...">) in the character count. The image source tag — which can be dozens of characters long — counts against the character limit of the field. When a rich text field contains multiple images, the cumulative length of all image tags can cause STRING_TOO_LONG errors even when the visible text content is short.
See Rich Text Area Field Limitations — Salesforce Help for the full list of restrictions : https://help.salesforce.com/s/articleView?id=platform.fields_rich_text_area_limitations.htm&type=5
000382141

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.