function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Victoria WintersVictoria Winters 

Trigger to truncate email header for email-to-case

We have encountered an issue with some cases coming in through email-to-case that bouce back becasue the string is too long and exceeds the 32,000 character limit. Support says this is hard coded and cannot increase the limit. The issue is the header that Microsoft is appending to the emails as pushing it over the limit and IT has spoken with them and this also cannot be adjusted. The recommendation from support is to write a trigger to truncate the email header. Since I am not a developer I don't know how to write this trigger. Curious if anyone else has done something like this already. I have looked through the community and can't find much info on this. Any guidance would be much appreciated!
Best Answer chosen by Victoria Winters
Kevin DiLoretoKevin DiLoreto
Oops, just realized the issue is with the Description, not the Subject. You should be able to replace the all words "Subject" with "Description" and replace all "255" with "32000" and everything should work.

All Answers

Kevin DiLoretoKevin DiLoreto
Hi Victoria, I’m not sure how versed you are in triggers, so I wrote out all of the steps you would need to take. I assume you are receiving this error from the Case Subject. If that’s true, then here’s a solution…
  1. Open the “Developer Console”
  2. Navigate to FileàNewà Apex Trigger
  3. Name: Enter this info
    1. Name: CaseTruncateSubject
    2. sObject: Case
  4. Paste the below code in and click save

trigger CaseTruncateSubject on Case (before insert) {
    For(Case c :Trigger.New){
        If(c.Subject!=null){
            Integer MySubjectLength = c.Subject.Length();
            If(MySubjectLength > 255){
                c.Subject = c.Subject.substring(0,255);
            }
        }
    }
}
        5. Navigate to FileàNewà Apex Class

        6. Enter this info:
               1. Name: CaseTruncateSubject_TEST
               2. Paste the below code in and click save 
 
@IsTest
public class CaseTruncateSubject_TEST {
     static testMethod void Truncate() {
          Case c=new           Case(Description='1',Subject='1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111');
insert c;
}
}
 
   7. Test the email to case using a subject longer than 255 characters
Kevin DiLoretoKevin DiLoreto
Oops, just realized the issue is with the Description, not the Subject. You should be able to replace the all words "Subject" with "Description" and replace all "255" with "32000" and everything should work.
This was selected as the best answer
Victoria WintersVictoria Winters
Thank you this is very helpful!