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
Manpreet Singh 207Manpreet Singh 207 

Wrote trigger to block case creation with specific Subject line

Hello All - We have created below mentioned trigger to block emails from creating cases with specific subject lines

trigger manageEmailCases on Case (before insert) {

    List<String> oooSubjects=new List<String>{'OOO','ooo','Automatic Reply','automatic reply','Automatic reply'};
    for(Case thisCase : trigger.new) {
        if(thisCase.Origin == 'Email') {
          // String sub = thisCase.Subject;   
            String s = thisCase.Subject;
    
             if(oooSubjects.contains(s)) {
                        
         }
        }
            {
                thisCase.description.addError('Not saving e2c');
            }
        }
    }

However, it has blocked an email from case creation with subject 'on line classes'. What could be the issue here?
Best Answer chosen by Manpreet Singh 207
Manpreet Singh 207Manpreet Singh 207
Anutej - We were able to fix the issue by updating the code. Here is the updated code


trigger manageEmailCases on Case (before insert) {

    List<String> oooSubjects=new List<String>{'OOO','ooo','Automatic Reply','automatic reply','Automatic reply'};
    for(Case thisCase : trigger.new) {
        if(thisCase.Origin == 'Email') {
          // String sub = thisCase.Subject;   
            String s = thisCase.Subject;
    
             if(oooSubjects.contains(s)) {
                        
    
                thisCase.description.addError('Not saving e2c');
             }
        
            }
        }
    }

All Answers

ANUTEJANUTEJ (Salesforce Developers) 
Hi Manpreet Singh,

This trigger might be causing the issue or there could be custom validation rule that might be set up that might be preventing from the cse creation to check what you could do is set the debug logs on default case owner and try replicating the scenario then after following the steps you can check the debug logs to check what might be causing the issue.

In case if this helps please close the thread by marking a best answer so that it can be helpful to others in the future and also helps in keeping the community clean.

Regards,
Anutej
Manpreet Singh 207Manpreet Singh 207
Anutej - We were able to fix the issue by updating the code. Here is the updated code


trigger manageEmailCases on Case (before insert) {

    List<String> oooSubjects=new List<String>{'OOO','ooo','Automatic Reply','automatic reply','Automatic reply'};
    for(Case thisCase : trigger.new) {
        if(thisCase.Origin == 'Email') {
          // String sub = thisCase.Subject;   
            String s = thisCase.Subject;
    
             if(oooSubjects.contains(s)) {
                        
    
                thisCase.description.addError('Not saving e2c');
             }
        
            }
        }
    }
This was selected as the best answer