+ Start a Discussion

Issue with creating test cases and failure to deploy to production

We have a number of classes/triggers that are brand spankin' new to the salesforce site.  Many of the fields that they are using are not currently in production.  I have created the test cases for each and every class and trigger, and when running those tests against our staging environment, they work just fine.


However, when I attempt to "validate" the changes to move to prod, many of these classes/triggers are failing with this error message:


System.QueryExpression: List has no rows for assignment to SObject.

 Class.createProjectTestClass.myUnitTest: line 27, column 21 External entry point


Looking at the test case, the reason is, the "select" statement isn't bringing anything back since the data to support the test case doesn't exist in production.




--Todd Kruse


Best Answer chosen by Admin (Salesforce Developers) 

You'd normally handle this by creating the data for your test as part of the test itself e.g. insert any accounts/contacts etc that are required to execute the test up front.


One thing to bear in mind is that any existing data will be returned unless you exclude it.