You need to sign in to do that
Don't have an account?
Jennifer.Schnell
Apex Test Failure - System.QueryException: List has no rows for assignment to SObject
I am receiving an apex test error - the error message is:
System.QueryException: List has no rows for assignment to SObject
Stack Trace: Class.BillingScheduleTest.TestBillingSchedule2: line 108, column 1
When I view the code in the developer console - line 108 code is the below:
Asset objAS = [Select Id,Contract__c,Name From Asset Where Name= 'TestAsset' Limit 1];
Still learning a lot of this stuff, but is the error telling me that I don't have an Asset with the name "TestAsset"?
Thanks.
System.QueryException: List has no rows for assignment to SObject
Stack Trace: Class.BillingScheduleTest.TestBillingSchedule2: line 108, column 1
When I view the code in the developer console - line 108 code is the below:
Asset objAS = [Select Id,Contract__c,Name From Asset Where Name= 'TestAsset' Limit 1];
Still learning a lot of this stuff, but is the error telling me that I don't have an Asset with the name "TestAsset"?
Thanks.
Did you create the test record in your test class? Because test classes can not access the org data untill or unless explicitly instructed to do so (@isTest(setALlData = True)). Secondly one should retrieve the SOQL records in a list variable because SOQL returns a list of the sObjects even if it fetches one record. For example :
Using a list also helps you to check a condition over the size of the list (as mentioned in the code above) and prevents to fall in to nullpointer exception trap.
Hope this helps.
Cheers,
Dev
Hi Jennifer,
Please make sure you have Asset record named "TestAsset" with Contract__c.
First you add @isTest(SeeAllData=true) above the TestBillingSchedule2() method Like:
try this hope it will help you.
For More information:- https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_seealldata_using.htm
Mark as a best if it helps you.
Regards,
Suraj
I looked in to your code, it seems correct to me. Could you please post the error along with the trace, that will help to dig more.
Viele Grüße,
Dev
Method: TestBillingSchedule2
Error Message: System.QueryException: List has no rows for assignment to SObject
Stack Trace: Class.BillingScheduleTest.TestBillingSchedule2: line 108, column 1