• Chenjie Li
  • NEWBIE
  • 15 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies
Hi fellow developers:

I am working on an apex trigger that will assign cases to certain groups/users based on the requirements from my boss.

What is really bothering me now is that when i ran the test class in sandbox it worked perfectly but when trying to deploy in production it gives me the following error:

First exception on row 2 with id 5003a00000xQsOrAAK; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []
Stack Trace: Class.TestCaseTrigger.TestCaseStatusChange: line 101, column 1


the trigger code:
trigger CaseTrigger on Case (before update) {
    for(Case c:Trigger.New){
        // grab the version of this case before the update 
        Case oldcase = Trigger.oldMap.get(c.ID);
        // access the status before the update for this case 
        string old_status = oldcase.status;
        // access the status after the update for this case
        string new_status = c.status;
        if(old_status == 'Closed' && new_status != 'Closed'){
          // we only need to handle this scenario, for now
          boolean previous_onwer_isactive = [SELECT owner.isActive FROM case WHERE id = :oldcase.Id LIMIT 1].owner.isactive;
            if(previous_onwer_isactive==FALSE){
                // create the rules based on "Case Assignment Rule"
                string case_subject = [SELECT subject FROM case WHERE id = :c.id LIMIT 1].subject;
                string case_origin = [SELECT origin FROM case WHERE id = :c.id LIMIT 1].origin;
                string assigned_to_name; // a variable used to locate its corresponding ID later on
                string assigned_to_id;
                
                if((case_subject=='HCRC TR Files'||case_subject=='HCRC FY Files') && case_origin == 
                   'Email - Enrollment Process Intelligence'){
                       assigned_to_name = 'HCRC Files';
                }
                else if(case_origin == 'Email - Enrollment Process Intelligence'){
                    assigned_to_name = 'Enrollment Process Intelligence';
                }
                else if(case_origin == 'Email - Enrollment Reporting'){
                    assigned_to_name = 'Enrollment Reporting';
                }
                else if(case_origin == 'Email - Enrollment Support'){
                    assigned_to_name = 'Tim';
                }
                else if(case_origin =='Email - Elevate'){
                    assigned_to_name = 'Elevate';
                }
                else if(case_origin =='Email - Graduate Admission'){
                    assigned_to_name = 'Graduate Admission Case Queue';
                }
                else if(case_origin =='Email - Graduate Recruitment'){
                    assigned_to_name = 'Graduate Recruitment';
                }
                else if(case_origin =='Email - Graduate Visit'){
                    assigned_to_name = 'Graduate Visit Case Queue';
                }
                else if(case_origin =='Email - GR Admission Partner'){
                    assigned_to_name = 'GR Admission Partner';
                }               
                else if(case_origin =='Email - UG Admission Partner'){
                    assigned_to_name = 'UG Admission Partner';
                }
                else if(case_origin =='Olark Live Chat' || case_origin == 'Graduate SnapEngage Chat'){
                    assigned_to_name = 'Graduate Recruitment';
                }
                else if(case_origin =='Web'){
                    assigned_to_name = 'Enrollment Process Intelligence';
                }
                else if(case_origin =='Email - Undergraduate Admission'){
                    assigned_to_name = 'Undergraduate Admission';
                }
                else if(case_origin =='Email - Undergraduate International'){
                    assigned_to_name = 'Undergraduate International';
                }
                else if(case_origin =='Email - Undergraduate Visit'){
                    assigned_to_name = 'Undergraduate Visit';
                }                    
                else if(case_origin =='Form Assembly - Project Request'){
                    assigned_to_name = 'Enrollment Process Intelligence';
                }
                else if(case_origin =='Email - Undergraduate Transfer'){
                    assigned_to_name = 'Undergraduate Transfer';
                }                
                else if(case_origin =='Email-Academic Honesty'){
                    assigned_to_name = 'Academic Honesty';
                }                
                else{
                    c.addError('did not find a queue/person to assign to!');
                    break;
                }
                
                // only Tim is not a queue(Group object), so handled seperately
                if(assigned_to_name !='Tim'){
                    assigned_to_id = [SELECT id FROM group where name =:assigned_to_name LIMIT 1].id;
                }
                else{
                     assigned_to_id = '005j000000COiwwAAD';
                }
               
                c.OwnerId = assigned_to_id;

                                
            }
        }
        
        
    }
}

trigger test class:
@isTest
public class TestCaseTrigger {
    @isTest static void TestCaseStatusChange(){
        // set up the data
        // create an user(owner)
        
        User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];

        System.runAs (thisUser){
        
        User test_user = new User(ProfileId = [SELECT Id FROM Profile WHERE Name = 'Standard User'].Id,
                          LastName = 'James',
                          Email = 'cli112@gmail.com',
                          Username = 'newlbj@gmail.com',
                          CompanyName = 'TEST',
                          Title = 'title',
                          Alias = 'alias',
                          TimeZoneSidKey = 'America/Los_Angeles',
                          EmailEncodingKey = 'UTF-8',
                          LanguageLocaleKey = 'en_US',
                          LocaleSidKey = 'en_US',
                          isactive =  FALSE
                         );
        
        
        insert test_user;
            
        // create a case
        string test_user_id = [SELECT id from user where username='newlbj@gmail.com' limit 1].id;
        // 

        List<Case> testCases = new List<Case>();
        Case test_case1 = New Case(origin='Email - Enrollment Process Intelligence', subject = 'HCRC TR Files',
         status='Closed', IIT_Project_Name__c = 'Test Case1',ownerid = test_user_id);
        testCases.add(test_case1);
        Case test_case2 = New Case(origin='Email - Enrollment Process Intelligence', subject = 'different subject', 
            status='Closed', IIT_Project_Name__c = 'Test Case2',ownerid = test_user_id);
        testCases.add(test_case2);
        Case test_case3 = New Case(origin='Email - Enrollment Reporting', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case3',ownerid = test_user_id);
        testCases.add(test_case3);
        //Case test_case4 = New Case(origin='Email - Enrollment Support', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case4',ownerid = test_user_id);
        testCases.add(test_case4);
        Case test_case5 = New Case(origin='Email - Elevate', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case5',ownerid = test_user_id);
        testCases.add(test_case5);
        Case test_case6 = New Case(origin='Email - Graduate Admission', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case6',ownerid = test_user_id);
        testCases.add(test_case6);
        Case test_case7 = New Case(origin='Email - Graduate Recruitment', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case7',ownerid = test_user_id);
        testCases.add(test_case7);
        Case test_case8 = New Case(origin='Email - Graduate Visit', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case8',ownerid = test_user_id);
        testCases.add(test_case8);
        Case test_case9 = New Case(origin='Email - GR Admission Partner', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case9',ownerid = test_user_id);
        testCases.add(test_case9);
        Case test_case10 = New Case(origin='Email - UG Admission Partner', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case10',ownerid = test_user_id);
        testCases.add(test_case10);
        Case test_case11 = New Case(origin='Olark Live Chat', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case11',ownerid = test_user_id);
        testCases.add(test_case11);
        Case test_case12 = New Case(origin='Web', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case12',ownerid = test_user_id);
        testCases.add(test_case12);
        Case test_case13 = New Case(origin='Email - Undergraduate Admission', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case13',ownerid = test_user_id);
        testCases.add(test_case13);
        Case test_case14 = New Case(origin='Email - Undergraduate International', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case14',ownerid = test_user_id);
        testCases.add(test_case14);
        Case test_case15 = New Case(origin='Email - Undergraduate Visit', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case15',ownerid = test_user_id);
        testCases.add(test_case15);
        Case test_case16 = New Case(origin='Form Assembly - Project Request', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case16',ownerid = test_user_id);
        testCases.add(test_case16);
        Case test_case17 = New Case(origin='Email - Undergraduate Transfer', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case17',ownerid = test_user_id);
        testCases.add(test_case17);
        Case test_case18 = New Case(origin='Email-Academic Honesty', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case18',ownerid = test_user_id);
        testCases.add(test_case18);

        insert testCases;
            
        
        // select all the test cases and then update them to status as "In Progress"
        List<Case> newstatusCases = [SELECT origin, subject, Status, ownerid FROM case WHERE IIT_Project_Name__c LIKE 'Test Case%'];
            
        for(Case c : newstatusCases){
            c.Status = 'In Progress';
        }
            
        system.debug('Size of newstatusCases: ');
        system.debug(newstatusCases.size());

        update newstatusCases;
        
            
        Test.startTest();

        // test1 : 'Email - Enrollment Process Intelligence' --> 'HCRC Files'
        Case inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case1' LIMIT 1];
        string test1_owner_id = inserted_test_case.OwnerId;
        
        test2 : 'Email - Enrollment Process Intelligence' --> 'Enrollment Process Intelligence'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case2' LIMIT 1];
        string test2_owner_id = inserted_test_case.OwnerId;
        
        // test3 : 'Email - Enrollment Reporting' --> 'Enrollment Reporting'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case3' LIMIT 1];
        string test3_owner_id = inserted_test_case.OwnerId;
            
            
        test4 : 'Email - Enrollment Support' --> 'Tim'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case4' LIMIT 1];
        string test4_owner_id = inserted_test_case.OwnerId;
        
        // test5 : 'Email - Elevate' --> 'Email - Elevate'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case5' LIMIT 1];
        string test5_owner_id = inserted_test_case.OwnerId;
        
        // test6 : 'Email - Graduate Admission' --> 'Graduate Admission Case Queue'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case6' LIMIT 1];
        string test6_owner_id = inserted_test_case.OwnerId;

        // test7 : 'Email - Graduate Recruitment' --> 'Graduate Recruitment'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case7' LIMIT 1];
        string test7_owner_id = inserted_test_case.OwnerId;

        // test8 : 'Email - Graduate Visit' --> 'Graduate Visit Case Queue'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case8' LIMIT 1];
        string test8_owner_id = inserted_test_case.OwnerId;            
 
        // test9 : 'Email - GR Admission Partner' --> 'GR Admission Partner'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case9' LIMIT 1];
        string test9_owner_id = inserted_test_case.OwnerId; 
            
        // test10 : 'Email - UG Admission Partner' --> 'UG Admission Partner'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case10' LIMIT 1];
        string test10_owner_id = inserted_test_case.OwnerId;

        // test11 : 'Olark Live Chat' --> 'Graduate Recruitment'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case11' LIMIT 1];
        string test11_owner_id = inserted_test_case.OwnerId;

        // test12 : 'Web' --> 'Enrollment Process Intelligence'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case12' LIMIT 1];
        string test12_owner_id = inserted_test_case.OwnerId;            

        // test13 : 'Email - Undergraduate Admission' --> 'Undergraduate Admission'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case13' LIMIT 1];
        string test13_owner_id = inserted_test_case.OwnerId;            

        // test14 : 'Email - Undergraduate International' --> 'Undergraduate International'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case14' LIMIT 1];
        string test14_owner_id = inserted_test_case.OwnerId;            

        // test15 : 'Email - Undergraduate Visit' --> 'Undergraduate Visit'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case15' LIMIT 1];
        string test15_owner_id = inserted_test_case.OwnerId;            
        
        // test16 : 'Form Assembly - Project Request' --> 'Enrollment Process Intelligence'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case16' LIMIT 1];
        string test16_owner_id = inserted_test_case.OwnerId;              
            
        // test17 : 'Email - Undergraduate Transfer' --> 'Undergraduate Transfer'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case17' LIMIT 1];
        string test17_owner_id = inserted_test_case.OwnerId;              
            
        // test18 : 'Email-Academic Honesty' --> 'Academic Honesty'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case18' LIMIT 1];
        string test18_owner_id = inserted_test_case.OwnerId;            
            
        
            
        Test.stopTest();

            
            
            
            
            
        // Tests validations

        string test1_correct_owner_id = [SELECT id FROM group where name = 'HCRC Files' LIMIT 1].id;
        System.assertEquals(test1_owner_id,test1_correct_owner_id);

        string test2_correct_owner_id = [SELECT id FROM group where name = 'Enrollment Process Intelligence' LIMIT 1].id;
        System.assertEquals(test2_owner_id,test2_correct_owner_id);
            
        string test3_correct_owner_id = [SELECT id FROM group where name = 'Enrollment Reporting' LIMIT 1].id;
        System.assertEquals(test3_owner_id,test3_correct_owner_id);
            
        string test4_correct_owner_id = '005j000000COiwwAAD';
        System.assertEquals(test4_owner_id,test4_correct_owner_id);

        string test5_correct_owner_id = [SELECT id FROM group where name = 'Elevate' LIMIT 1].id;
        System.assertEquals(test5_owner_id,test5_correct_owner_id);
        
        string test6_correct_owner_id = [SELECT id FROM group where name = 'Graduate Admission Case Queue' LIMIT 1].id;
        System.assertEquals(test6_owner_id,test6_correct_owner_id);

        string test7_correct_owner_id = [SELECT id FROM group where name = 'Graduate Recruitment' LIMIT 1].id;
        System.assertEquals(test7_owner_id,test7_correct_owner_id);

        string test8_correct_owner_id = [SELECT id FROM group where name = 'Graduate Visit Case Queue' LIMIT 1].id;
        System.assertEquals(test8_owner_id,test8_correct_owner_id);

        string test9_correct_owner_id = [SELECT id FROM group where name = 'GR Admission Partner' LIMIT 1].id;
        System.assertEquals(test9_owner_id,test9_correct_owner_id);

        string test10_correct_owner_id = [SELECT id FROM group where name = 'UG Admission Partner' LIMIT 1].id;
        System.assertEquals(test10_owner_id,test10_correct_owner_id);            

        string test11_correct_owner_id = [SELECT id FROM group where name = 'Graduate Recruitment' LIMIT 1].id;
        System.assertEquals(test11_owner_id,test11_correct_owner_id);            
            
        string test12_correct_owner_id = [SELECT id FROM group where name = 'Enrollment Process Intelligence' LIMIT 1].id;
        System.assertEquals(test12_owner_id,test12_correct_owner_id);
        
        string test13_correct_owner_id = [SELECT id FROM group where name = 'Undergraduate Admission' LIMIT 1].id;
        System.assertEquals(test13_owner_id,test13_correct_owner_id); 
            
        string test14_correct_owner_id = [SELECT id FROM group where name = 'Undergraduate International' LIMIT 1].id;
        System.assertEquals(test14_owner_id,test14_correct_owner_id);              
            
        string test15_correct_owner_id = [SELECT id FROM group where name = 'Undergraduate Visit' LIMIT 1].id;
        System.assertEquals(test15_owner_id,test15_correct_owner_id);              
        
        string test16_correct_owner_id = [SELECT id FROM group where name = 'Enrollment Process Intelligence' LIMIT 1].id;
        System.assertEquals(test16_owner_id,test16_correct_owner_id);              
            
        string test17_correct_owner_id = [SELECT id FROM group where name = 'Undergraduate Transfer' LIMIT 1].id;
        System.assertEquals(test17_owner_id,test17_correct_owner_id);              
            
        string test18_correct_owner_id = [SELECT id FROM group where name = 'Academic Honesty' LIMIT 1].id;
        System.assertEquals(test18_owner_id,test18_correct_owner_id);  
             
            // new_case.OwnerId;
    }
    }
}

 
Hi fellow developers:

I am working on an apex trigger that will assign cases to certain groups/users based on the requirements from my boss.

What is really bothering me now is that when i ran the test class in sandbox it worked perfectly but when trying to deploy in production it gives me the following error:

First exception on row 2 with id 5003a00000xQsOrAAK; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []
Stack Trace: Class.TestCaseTrigger.TestCaseStatusChange: line 101, column 1


the trigger code:
trigger CaseTrigger on Case (before update) {
    for(Case c:Trigger.New){
        // grab the version of this case before the update 
        Case oldcase = Trigger.oldMap.get(c.ID);
        // access the status before the update for this case 
        string old_status = oldcase.status;
        // access the status after the update for this case
        string new_status = c.status;
        if(old_status == 'Closed' && new_status != 'Closed'){
          // we only need to handle this scenario, for now
          boolean previous_onwer_isactive = [SELECT owner.isActive FROM case WHERE id = :oldcase.Id LIMIT 1].owner.isactive;
            if(previous_onwer_isactive==FALSE){
                // create the rules based on "Case Assignment Rule"
                string case_subject = [SELECT subject FROM case WHERE id = :c.id LIMIT 1].subject;
                string case_origin = [SELECT origin FROM case WHERE id = :c.id LIMIT 1].origin;
                string assigned_to_name; // a variable used to locate its corresponding ID later on
                string assigned_to_id;
                
                if((case_subject=='HCRC TR Files'||case_subject=='HCRC FY Files') && case_origin == 
                   'Email - Enrollment Process Intelligence'){
                       assigned_to_name = 'HCRC Files';
                }
                else if(case_origin == 'Email - Enrollment Process Intelligence'){
                    assigned_to_name = 'Enrollment Process Intelligence';
                }
                else if(case_origin == 'Email - Enrollment Reporting'){
                    assigned_to_name = 'Enrollment Reporting';
                }
                else if(case_origin == 'Email - Enrollment Support'){
                    assigned_to_name = 'Tim';
                }
                else if(case_origin =='Email - Elevate'){
                    assigned_to_name = 'Elevate';
                }
                else if(case_origin =='Email - Graduate Admission'){
                    assigned_to_name = 'Graduate Admission Case Queue';
                }
                else if(case_origin =='Email - Graduate Recruitment'){
                    assigned_to_name = 'Graduate Recruitment';
                }
                else if(case_origin =='Email - Graduate Visit'){
                    assigned_to_name = 'Graduate Visit Case Queue';
                }
                else if(case_origin =='Email - GR Admission Partner'){
                    assigned_to_name = 'GR Admission Partner';
                }               
                else if(case_origin =='Email - UG Admission Partner'){
                    assigned_to_name = 'UG Admission Partner';
                }
                else if(case_origin =='Olark Live Chat' || case_origin == 'Graduate SnapEngage Chat'){
                    assigned_to_name = 'Graduate Recruitment';
                }
                else if(case_origin =='Web'){
                    assigned_to_name = 'Enrollment Process Intelligence';
                }
                else if(case_origin =='Email - Undergraduate Admission'){
                    assigned_to_name = 'Undergraduate Admission';
                }
                else if(case_origin =='Email - Undergraduate International'){
                    assigned_to_name = 'Undergraduate International';
                }
                else if(case_origin =='Email - Undergraduate Visit'){
                    assigned_to_name = 'Undergraduate Visit';
                }                    
                else if(case_origin =='Form Assembly - Project Request'){
                    assigned_to_name = 'Enrollment Process Intelligence';
                }
                else if(case_origin =='Email - Undergraduate Transfer'){
                    assigned_to_name = 'Undergraduate Transfer';
                }                
                else if(case_origin =='Email-Academic Honesty'){
                    assigned_to_name = 'Academic Honesty';
                }                
                else{
                    c.addError('did not find a queue/person to assign to!');
                    break;
                }
                
                // only Tim is not a queue(Group object), so handled seperately
                if(assigned_to_name !='Tim'){
                    assigned_to_id = [SELECT id FROM group where name =:assigned_to_name LIMIT 1].id;
                }
                else{
                     assigned_to_id = '005j000000COiwwAAD';
                }
               
                c.OwnerId = assigned_to_id;

                                
            }
        }
        
        
    }
}

trigger test class:
@isTest
public class TestCaseTrigger {
    @isTest static void TestCaseStatusChange(){
        // set up the data
        // create an user(owner)
        
        User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];

        System.runAs (thisUser){
        
        User test_user = new User(ProfileId = [SELECT Id FROM Profile WHERE Name = 'Standard User'].Id,
                          LastName = 'James',
                          Email = 'cli112@gmail.com',
                          Username = 'newlbj@gmail.com',
                          CompanyName = 'TEST',
                          Title = 'title',
                          Alias = 'alias',
                          TimeZoneSidKey = 'America/Los_Angeles',
                          EmailEncodingKey = 'UTF-8',
                          LanguageLocaleKey = 'en_US',
                          LocaleSidKey = 'en_US',
                          isactive =  FALSE
                         );
        
        
        insert test_user;
            
        // create a case
        string test_user_id = [SELECT id from user where username='newlbj@gmail.com' limit 1].id;
        // 

        List<Case> testCases = new List<Case>();
        Case test_case1 = New Case(origin='Email - Enrollment Process Intelligence', subject = 'HCRC TR Files',
         status='Closed', IIT_Project_Name__c = 'Test Case1',ownerid = test_user_id);
        testCases.add(test_case1);
        Case test_case2 = New Case(origin='Email - Enrollment Process Intelligence', subject = 'different subject', 
            status='Closed', IIT_Project_Name__c = 'Test Case2',ownerid = test_user_id);
        testCases.add(test_case2);
        Case test_case3 = New Case(origin='Email - Enrollment Reporting', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case3',ownerid = test_user_id);
        testCases.add(test_case3);
        //Case test_case4 = New Case(origin='Email - Enrollment Support', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case4',ownerid = test_user_id);
        testCases.add(test_case4);
        Case test_case5 = New Case(origin='Email - Elevate', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case5',ownerid = test_user_id);
        testCases.add(test_case5);
        Case test_case6 = New Case(origin='Email - Graduate Admission', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case6',ownerid = test_user_id);
        testCases.add(test_case6);
        Case test_case7 = New Case(origin='Email - Graduate Recruitment', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case7',ownerid = test_user_id);
        testCases.add(test_case7);
        Case test_case8 = New Case(origin='Email - Graduate Visit', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case8',ownerid = test_user_id);
        testCases.add(test_case8);
        Case test_case9 = New Case(origin='Email - GR Admission Partner', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case9',ownerid = test_user_id);
        testCases.add(test_case9);
        Case test_case10 = New Case(origin='Email - UG Admission Partner', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case10',ownerid = test_user_id);
        testCases.add(test_case10);
        Case test_case11 = New Case(origin='Olark Live Chat', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case11',ownerid = test_user_id);
        testCases.add(test_case11);
        Case test_case12 = New Case(origin='Web', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case12',ownerid = test_user_id);
        testCases.add(test_case12);
        Case test_case13 = New Case(origin='Email - Undergraduate Admission', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case13',ownerid = test_user_id);
        testCases.add(test_case13);
        Case test_case14 = New Case(origin='Email - Undergraduate International', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case14',ownerid = test_user_id);
        testCases.add(test_case14);
        Case test_case15 = New Case(origin='Email - Undergraduate Visit', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case15',ownerid = test_user_id);
        testCases.add(test_case15);
        Case test_case16 = New Case(origin='Form Assembly - Project Request', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case16',ownerid = test_user_id);
        testCases.add(test_case16);
        Case test_case17 = New Case(origin='Email - Undergraduate Transfer', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case17',ownerid = test_user_id);
        testCases.add(test_case17);
        Case test_case18 = New Case(origin='Email-Academic Honesty', subject = 'HCRC TR Files', 
            status='Closed', IIT_Project_Name__c = 'Test Case18',ownerid = test_user_id);
        testCases.add(test_case18);

        insert testCases;
            
        
        // select all the test cases and then update them to status as "In Progress"
        List<Case> newstatusCases = [SELECT origin, subject, Status, ownerid FROM case WHERE IIT_Project_Name__c LIKE 'Test Case%'];
            
        for(Case c : newstatusCases){
            c.Status = 'In Progress';
        }
            
        system.debug('Size of newstatusCases: ');
        system.debug(newstatusCases.size());

        update newstatusCases;
        
            
        Test.startTest();

        // test1 : 'Email - Enrollment Process Intelligence' --> 'HCRC Files'
        Case inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case1' LIMIT 1];
        string test1_owner_id = inserted_test_case.OwnerId;
        
        test2 : 'Email - Enrollment Process Intelligence' --> 'Enrollment Process Intelligence'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case2' LIMIT 1];
        string test2_owner_id = inserted_test_case.OwnerId;
        
        // test3 : 'Email - Enrollment Reporting' --> 'Enrollment Reporting'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case3' LIMIT 1];
        string test3_owner_id = inserted_test_case.OwnerId;
            
            
        test4 : 'Email - Enrollment Support' --> 'Tim'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case4' LIMIT 1];
        string test4_owner_id = inserted_test_case.OwnerId;
        
        // test5 : 'Email - Elevate' --> 'Email - Elevate'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case5' LIMIT 1];
        string test5_owner_id = inserted_test_case.OwnerId;
        
        // test6 : 'Email - Graduate Admission' --> 'Graduate Admission Case Queue'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case6' LIMIT 1];
        string test6_owner_id = inserted_test_case.OwnerId;

        // test7 : 'Email - Graduate Recruitment' --> 'Graduate Recruitment'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case7' LIMIT 1];
        string test7_owner_id = inserted_test_case.OwnerId;

        // test8 : 'Email - Graduate Visit' --> 'Graduate Visit Case Queue'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case8' LIMIT 1];
        string test8_owner_id = inserted_test_case.OwnerId;            
 
        // test9 : 'Email - GR Admission Partner' --> 'GR Admission Partner'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case9' LIMIT 1];
        string test9_owner_id = inserted_test_case.OwnerId; 
            
        // test10 : 'Email - UG Admission Partner' --> 'UG Admission Partner'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case10' LIMIT 1];
        string test10_owner_id = inserted_test_case.OwnerId;

        // test11 : 'Olark Live Chat' --> 'Graduate Recruitment'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case11' LIMIT 1];
        string test11_owner_id = inserted_test_case.OwnerId;

        // test12 : 'Web' --> 'Enrollment Process Intelligence'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case12' LIMIT 1];
        string test12_owner_id = inserted_test_case.OwnerId;            

        // test13 : 'Email - Undergraduate Admission' --> 'Undergraduate Admission'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case13' LIMIT 1];
        string test13_owner_id = inserted_test_case.OwnerId;            

        // test14 : 'Email - Undergraduate International' --> 'Undergraduate International'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case14' LIMIT 1];
        string test14_owner_id = inserted_test_case.OwnerId;            

        // test15 : 'Email - Undergraduate Visit' --> 'Undergraduate Visit'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case15' LIMIT 1];
        string test15_owner_id = inserted_test_case.OwnerId;            
        
        // test16 : 'Form Assembly - Project Request' --> 'Enrollment Process Intelligence'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case16' LIMIT 1];
        string test16_owner_id = inserted_test_case.OwnerId;              
            
        // test17 : 'Email - Undergraduate Transfer' --> 'Undergraduate Transfer'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case17' LIMIT 1];
        string test17_owner_id = inserted_test_case.OwnerId;              
            
        // test18 : 'Email-Academic Honesty' --> 'Academic Honesty'
        inserted_test_case = [SELECT origin, subject, status, ownerid FROM case WHERE IIT_Project_Name__c = 'Test Case18' LIMIT 1];
        string test18_owner_id = inserted_test_case.OwnerId;            
            
        
            
        Test.stopTest();

            
            
            
            
            
        // Tests validations

        string test1_correct_owner_id = [SELECT id FROM group where name = 'HCRC Files' LIMIT 1].id;
        System.assertEquals(test1_owner_id,test1_correct_owner_id);

        string test2_correct_owner_id = [SELECT id FROM group where name = 'Enrollment Process Intelligence' LIMIT 1].id;
        System.assertEquals(test2_owner_id,test2_correct_owner_id);
            
        string test3_correct_owner_id = [SELECT id FROM group where name = 'Enrollment Reporting' LIMIT 1].id;
        System.assertEquals(test3_owner_id,test3_correct_owner_id);
            
        string test4_correct_owner_id = '005j000000COiwwAAD';
        System.assertEquals(test4_owner_id,test4_correct_owner_id);

        string test5_correct_owner_id = [SELECT id FROM group where name = 'Elevate' LIMIT 1].id;
        System.assertEquals(test5_owner_id,test5_correct_owner_id);
        
        string test6_correct_owner_id = [SELECT id FROM group where name = 'Graduate Admission Case Queue' LIMIT 1].id;
        System.assertEquals(test6_owner_id,test6_correct_owner_id);

        string test7_correct_owner_id = [SELECT id FROM group where name = 'Graduate Recruitment' LIMIT 1].id;
        System.assertEquals(test7_owner_id,test7_correct_owner_id);

        string test8_correct_owner_id = [SELECT id FROM group where name = 'Graduate Visit Case Queue' LIMIT 1].id;
        System.assertEquals(test8_owner_id,test8_correct_owner_id);

        string test9_correct_owner_id = [SELECT id FROM group where name = 'GR Admission Partner' LIMIT 1].id;
        System.assertEquals(test9_owner_id,test9_correct_owner_id);

        string test10_correct_owner_id = [SELECT id FROM group where name = 'UG Admission Partner' LIMIT 1].id;
        System.assertEquals(test10_owner_id,test10_correct_owner_id);            

        string test11_correct_owner_id = [SELECT id FROM group where name = 'Graduate Recruitment' LIMIT 1].id;
        System.assertEquals(test11_owner_id,test11_correct_owner_id);            
            
        string test12_correct_owner_id = [SELECT id FROM group where name = 'Enrollment Process Intelligence' LIMIT 1].id;
        System.assertEquals(test12_owner_id,test12_correct_owner_id);
        
        string test13_correct_owner_id = [SELECT id FROM group where name = 'Undergraduate Admission' LIMIT 1].id;
        System.assertEquals(test13_owner_id,test13_correct_owner_id); 
            
        string test14_correct_owner_id = [SELECT id FROM group where name = 'Undergraduate International' LIMIT 1].id;
        System.assertEquals(test14_owner_id,test14_correct_owner_id);              
            
        string test15_correct_owner_id = [SELECT id FROM group where name = 'Undergraduate Visit' LIMIT 1].id;
        System.assertEquals(test15_owner_id,test15_correct_owner_id);              
        
        string test16_correct_owner_id = [SELECT id FROM group where name = 'Enrollment Process Intelligence' LIMIT 1].id;
        System.assertEquals(test16_owner_id,test16_correct_owner_id);              
            
        string test17_correct_owner_id = [SELECT id FROM group where name = 'Undergraduate Transfer' LIMIT 1].id;
        System.assertEquals(test17_owner_id,test17_correct_owner_id);              
            
        string test18_correct_owner_id = [SELECT id FROM group where name = 'Academic Honesty' LIMIT 1].id;
        System.assertEquals(test18_owner_id,test18_correct_owner_id);  
             
            // new_case.OwnerId;
    }
    }
}