You need to sign in to do that
Don't have an account?
Meredith Salget 12
Receiving "INVALID_CROSS_REFERENCE_KEY, Owner ID: owner cannot be blank: [OwnerId]" error
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:
Thanks!
Meredith
@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
You code snippet is test. This TestMethod not view all database, you need initialize Trash_Queue__c settings.
i Recomended u to use @testSetup method
As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.
Thanks,
Alex
It looks like what I actually need to do to access the data in the org is to use IsTest(SeeAllData=true).
No more than one executeBatch can be called from within a testmethod. Please make sure the iterable returned from your start method matches the batch size, resulting in one executeBatch invocation. External entry point
Guess I'm going to have to start from the beginning.
Its not a good practice to use IsTest(SeeAllData=true). When Developer sandbox doesn't have any data your test class would fail. Best Practice is you should always create test data in your test method.
Thanks!
Meredith
All custom settings etc should be created at run time, for the reasons noted above.