+ Start a Discussion
Patrick Mayer 4Patrick Mayer 4 

INVALID_CROSS_REFERENCE_KEY blocking all other deploys

Line 16 where I insert c1 I am getting a "System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []" error. This is blocking all other deploys
@isTest (seeAllData=true)
public class IdleCaseTriggerTest{
    
	static testMethod void test() {
        Group genCaseQueue = new Group();
        genCaseQueue.Name = 'General Case Queue';
        insert genCaseQueue;
       	Group[] queues = [select Id, Name 
              	          from Group 
             			  where Name = 'General Case Queue'];
   		String geq = queues[0].Id;
		Case c1 = new Case();
        Case c2 = new Case();
        c1.Idle_Case_Hidden__c = true;
        c1.OwnerId = genCaseQueue.Id;
        insert c1;
        insert c2;
        CronTrigger[] ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime
         			      FROM CronTrigger];
        System.debug(ct[0]);
        
        
        testCasePopup();
        testPopupPageController();
    }
    
    static testMethod void testCasePopUp() {
        CasePopup cpu = new CasePopup();
        System.assertEquals(false, cpu.ignoreOn);
        cpu.show();
        System.assertEquals(true, cpu.displayPopup);
        cpu.hide();
        System.assertEquals(false, cpu.displayPopup);
        cpu.ignoreToggle();
        System.assertEquals(true, cpu.ignoreOn);
        //System.assertEquals('Ignore Popups: On', cpu.getIgnoreText());
        cpu.ignoreToggle();
        System.assertEquals(false, cpu.ignoreOn);
        System.assertEquals('Ignore Popups: Off', cpu.getIgnoreText());
        
        cpu.checkCases();
    }
    
    static testMethod void testPopupPageController() {
        Group[] queues = [select Id, Name 
              	          from Group 
             			  where Name = 'General Case Queue'];
   		String geq = queues[0].Id;
		Case c = new Case();
        c.Idle_Case_Hidden__c = true;
        c.OwnerId = geq;
        insert c;
        PopupPageController ppc = new PopupPageController();
        List<Case> cl = ppc.getCases();
        //System.assertEquals(c.Id, cl[0].Id);
        //ppc.claim();
    }
        
}


ShashForceShashForce
Hi Patrick,

A record can only be owned by a user or a Queue, not a group. You are trying to make a group the owner of a record, which is not allowed. The group type should be a queue, like this:

        Group genCaseQueue = new Group();
        genCaseQueue.Name = 'General Case Queue';
        genCaseQueue.Type = 'Queue';
        insert genCaseQueue;
If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.

Thanks,
Shashank

Vinit_KumarVinit_Kumar
Couple of things I see in your code :-

1.)  You are inserting Group record and assigning the case to it.However a group can never be a case Owner,it can either be a Queue or a User.

2.) I don't see you are populating all the required fields which are required to insert a case record like Case Origin,Status.

Hope this helps !!