• Meredith Salget 12
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hello ~ I'm an admin that just started at a new company and cleaning up code of a developer that has left. There were a bunch of hard-coded Ids in code and configurations and I've attempted to replace them, in part, with a Custom Hierarchy Setting. I updated some code to reference the Id__c field on the custom setting instead of hard-coding the id, but I'm getting the "INVALID_CROSS_REFERENCE_KEY, Owner ID: owner cannot be blank: [OwnerId]" error. The code was hard-coding a Queue Id (named "Trash") and setting the owner of a Case record. My custom setting is named Trash_Queue__c. I've ensured that the Custom Setting is populated with the correct 18 character Id for the Queue. When I use execute anonymous to test if I am setting the trashQueue variable correctly, I get the result I want. What am I missing? Here is a snippet of the code:
 
@isTest
private class TestSchedulableClass {
    
    static testmethod void test() {
        test.startTest();
        
        Trash_Queue__c trashQueueSetting = Trash_Queue__c.getOrgDefaults();
            
        String trashQueue = trashQueueSetting.Id__c;
        
        Case delOldCase= new Case();
        delOldCase.OwnerId =trashQueue;
        insert delOldCase;

        Test.stopTest();   
     }
}

Thanks!
Meredith
Hello ~ I'm an admin that just started at a new company and cleaning up code of a developer that has left. There were a bunch of hard-coded Ids in code and configurations and I've attempted to replace them, in part, with a Custom Hierarchy Setting. I updated some code to reference the Id__c field on the custom setting instead of hard-coding the id, but I'm getting the "INVALID_CROSS_REFERENCE_KEY, Owner ID: owner cannot be blank: [OwnerId]" error. The code was hard-coding a Queue Id (named "Trash") and setting the owner of a Case record. My custom setting is named Trash_Queue__c. I've ensured that the Custom Setting is populated with the correct 18 character Id for the Queue. When I use execute anonymous to test if I am setting the trashQueue variable correctly, I get the result I want. What am I missing? Here is a snippet of the code:
 
@isTest
private class TestSchedulableClass {
    
    static testmethod void test() {
        test.startTest();
        
        Trash_Queue__c trashQueueSetting = Trash_Queue__c.getOrgDefaults();
            
        String trashQueue = trashQueueSetting.Id__c;
        
        Case delOldCase= new Case();
        delOldCase.OwnerId =trashQueue;
        insert delOldCase;

        Test.stopTest();   
     }
}

Thanks!
Meredith
Hello ~ I'm an admin that just started at a new company and cleaning up code of a developer that has left. There were a bunch of hard-coded Ids in code and configurations and I've attempted to replace them, in part, with a Custom Hierarchy Setting. I updated some code to reference the Id__c field on the custom setting instead of hard-coding the id, but I'm getting the "INVALID_CROSS_REFERENCE_KEY, Owner ID: owner cannot be blank: [OwnerId]" error. The code was hard-coding a Queue Id (named "Trash") and setting the owner of a Case record. My custom setting is named Trash_Queue__c. I've ensured that the Custom Setting is populated with the correct 18 character Id for the Queue. When I use execute anonymous to test if I am setting the trashQueue variable correctly, I get the result I want. What am I missing? Here is a snippet of the code:
 
@isTest
private class TestSchedulableClass {
    
    static testmethod void test() {
        test.startTest();
        
        Trash_Queue__c trashQueueSetting = Trash_Queue__c.getOrgDefaults();
            
        String trashQueue = trashQueueSetting.Id__c;
        
        Case delOldCase= new Case();
        delOldCase.OwnerId =trashQueue;
        insert delOldCase;

        Test.stopTest();   
     }
}

Thanks!
Meredith