You need to sign in to do that
Don't have an account?
JJE_OLD
SOQL return no rows
Hi,
I'm trying to write an apex test class
In eclipse Schema page I type the following SOQL request:
SELECT c.id FROM case c WHERE c.subject = 'Test Case' LIMIT 1
It works but when I'm trying to test this code:
@isTest private class testCaseTrigger { static testMethod void testCase() { Test.startTest(); Case cs = [SELECT c.id FROM case c WHERE c.subject = 'Test Case' LIMIT 1]; cs.CR_Delivery_Version__c = '7.2'; update cs; Case newCase = [SELECT crtargetrelease__c FROM case WHERE id =: cs.id]; system.assertEquals('MEGA 2009', newCase.CRTargetRelease__c); Test.stoptest(); } }
I get the following error : 'List has no rows for assignement to SObject'
I also tried the following: 'Select id FROM case', and I get also an empty list.
What is the problem?
thanks,
The Support told me to lower my Class API Version.
After changing from 24 to 20, it worked.
All Answers
Its looking for case record with subject as 'Test Case'.Please make sure u have that record in your sandbox.Then run the test class.
Yes, I tried the Request in eclipse and it returned 1 row.
I also tried to replace it with 'Select Id FROM Case' and it returned nothing, but I have 20 cases in my sandbox.
What could be the problem here?
Hi
Can u post ur Trigger.
Regards,
Rajesh.
The problem is not with the trigger wich is working fine in the sandbox but with the request:
Which is retruning nothing.
Hi
Try to insert the case manullay whose
and u will get and if u r writing the test class for trigger means plz post ur trigger code.
Regards,
Rajesh.
The Support told me to lower my Class API Version.
After changing from 24 to 20, it worked.
Does anyone know why this is true? This board provides solutions often times without explanation. I would like to know why API version 24 and 25 does not let you query in test classes. I have run into this so many times!
I don't know why, but I suppose that the goal was to isolate the test from the real data, maybe to separate the deployment as they allow since winter 13 to use test data in Static resources.
But as was suggested in this post, you could alway s use the following option to access the production data.
regards,