You need to sign in to do that
Don't have an account?
Miguel Roa
Custom object won't return anything
Hi, I'm new in APEX and I've been told to fix this test class:
@Istest Public class MillisecondBatchConvertController_Test{ public static testMethod void testBatch() { Team_Form__c tfCustom = new Team_Form__c(); tfCustom = [Select Id from Team_Form__c LIMIT 1]; List <PS_TF_Status_Track__c> stList = new List<PS_TF_Status_Track__c>(); for(integer count = 0; count<=1; count++){ PS_TF_Status_Track__c st = new PS_TF_Status_Track__c(Hours__c=count,Minutes__c=count,Days__c=count,Team_Form__c=tfCustom.Id); stList.add(st);} insert stList; Test.startTest(); MillisecondBatchConvertController mbcCon=new MillisecondBatchConvertController(); ID batchprocessid = Database.executeBatch(mbcCon,1); Test.stopTest(); } }
And I'm getting this error:
System.QueryException: List has no rows for assignment to SObject
I suppose this is because tfCustom.Id is empty but why is doesn't have any value?
Thanks in advance
The error states that there is no records that were returned from the soql query.
In test classes by default there is no access to the data in the org so you need to insert test data so before the soql you need to insert a record for Team_Form__c object. After inserting the record you can use fetch and perform the rest of the operations.
Try changing the below lines:
to something as below:
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.
All Answers
The error states that there is no records that were returned from the soql query.
In test classes by default there is no access to the data in the org so you need to insert test data so before the soql you need to insert a record for Team_Form__c object. After inserting the record you can use fetch and perform the rest of the operations.
Try changing the below lines:
to something as below:
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.
regards
Andrew