+ Start a Discussion
Wayne Cordrey 29Wayne Cordrey 29 

Tests fail with new API version

I'm updating a class/test class from version 23 to at least version 31.  When I do this, my test class fails.  Tracing the error, the line is here: 

Dashboard myDB = [SELECT Id FROM Dashboard LIMIT 1];  

@isTest
private class trac_Dashboard_Refresh_Test {

    @isTest static void myDashboardRefreshTest() {
                
        Dashboard myDB = [SELECT Id FROM Dashboard LIMIT 1];
       
        trac_Dashboard_Refresh_Controller dbr = new trac_Dashboard_Refresh_Controller();
        
        dbr.referrer = '/' + myDB.Id; 
        dbr.minutes = 0;       
        dbr.setup();        
        dbr.refreshDashboard();  
        
        
        }
}

When I run the query I get an ID, but this ID is not being stored in the Dashboard variable.  In looking at the Dashboard object, I don't see an Id field in the documentation.  

What do I need to do here to get the test working in at least V31?  Is my issue that I'm trying to save an Id value in an object that doesn't have an ID field?  Did this change over the versions because it works in V.23, but fails in V31.   

Oh yeah, error message: System.QueryException: List has no rows for assignment to SObject

I'm not the original developer here, just trying to move this to a current API version before deprecation.   Thanks for any pointers here! 

 

Best Answer chosen by Wayne Cordrey 29
Wayne Cordrey 29Wayne Cordrey 29
That did the trick.  Thanks for the quick reply Colin.  

All Answers

Colin KenworthyColin Kenworthy
Test Code in API v23.0 and earlier could see all Org data, as if it ran with @isTest(seeAllData=true). 
In later versions of the API you need to put it in your code because the default became @isTest(seeAllData=false). 
So change @isTest to @isTest(seeAllData=true) 
Wayne Cordrey 29Wayne Cordrey 29
That did the trick.  Thanks for the quick reply Colin.  
This was selected as the best answer