Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I am facing the issue on the case comment size. There is an inbound email handler which creates a case comment on a specific case record based on the incoming email body.

Sometimes its giving error - "STRING_TOO_LONG, Body: data value too large". Then i checked the limit for case comment body and its 4000 bytes and not characters.

Now the problem is how do i check for size of a string as bytes and not as characters in apex? I found that string .size() method returns number of characters and not no of bytes.

Please help.


share|improve this question

1 Answer 1

The documentation for String.length() (there is no String.size()) explains that it:

Returns the number of 16-bit Unicode characters contained in the String.

So the number of 8 bit bytes is 2x the length of the string. (And so to fix the problem you need to truncate at 2000 characters.)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.