+ Start a Discussion
Anto HotelbedsAnto Hotelbeds 

Email handler with chinese characters


I have an email handler for my EmailToCase. I am having errors when receiving an email with chinese characters.

What I do in my handler is take the body of the email, cut it to 4000char (max length of a case comment) and insert it as a case comment in the case. This is my handler code thats inserts the new case comment:

               system.debug('Longitud del comment: '+newCommand.CommentBody.length());
               system.debug('Comment length after cutting: '+newCommand.CommentBody.length());
             newCommand.IsPublished = TRUE;
             newCommand.ParentId =case.Id;
            insert newCommand;

When I make a debug, I receive that the length of the case comment I am about to insert is 3798, but I still get the error:

error: STRING_TOO_LONG, Body: data value too large:........... (max length=4000): [CommentBody]

This just happens with emails sent with chinese characters.

Did anyone face this issue before? Anyone has an idea on how to fix this?

Thanks a lot,

NehalNehal (Salesforce Developers) 

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, to 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.  Please refer to link below:


Also, using trim method :

Trim :
Returns a copy of the string that no longer contains any leading or trailing white space characters.
Leading and trailing ASCII control characters such as tabs and newline characters are also removed. White space and control characters that aren’t at the beginning or end of the sentence aren’t removed.


Further for your reference, please go through links below:


I hope this helps.