You need to sign in to do that
Don't have an account?
Gab Silvermotion
System.ListException: List index out of bounds: 0 in test class
Hi all,
I have this error 2 times in this test class.
System.ListException: List index out of bounds: 0
Class.FastSubmitAssetsClassTest.SubmitMultipleCaseTest: line 27, column 1
System.ListException: List index out of bounds: 0
Class.FastSubmitAssetsClassTest.SubmitSigleCaseTest: line 8, column 1
Code Sample :
I have this error 2 times in this test class.
System.ListException: List index out of bounds: 0
Class.FastSubmitAssetsClassTest.SubmitMultipleCaseTest: line 27, column 1
System.ListException: List index out of bounds: 0
Class.FastSubmitAssetsClassTest.SubmitSigleCaseTest: line 8, column 1
Code Sample :
@isTest(SeeAllData=true) Public Class FastSubmitAssetsClassTest{ // @IsTest Public Static Void SubmitSigleCaseTest(){ FastSubmitAssetsClass FsA=new FastSubmitAssetsClass(); FsA.SelectedId=FsA.assetContainers.get(0).cases.get(0).kase.id; system.assertNotEquals(NULL,FsA.SubmitForApproval()); PageReference submitPage=Page.FastSubmitAssetsPage; Test.setCurrentPageReference(submitPage); ApexPages.CurrentPage().getParameters().put('assetId',FsA.assetContainers.get(0).asset.id); system.assertNotEquals(NULL,FsA.SubmitForApproval()); //Action page testing PageReference actionPage=Page.FastSubmitActionPage; Test.setCurrentPageReference(actionPage); ApexPages.CurrentPage().getParameters().put('id',FsA.SelectedId); FastSubmitActionClass action=new FastSubmitActionClass(); system.assertEquals(NULL,action.yes()); system.assertNotEquals(NULL,action.no()); } @IsTest Public Static Void SubmitMultipleCaseTest(){ FastSubmitAssetsClass FsA=new FastSubmitAssetsClass(); FastSubmitAssetsClass.CaseContainer cc=FsA.assetContainers.get(0).cases.get(0); cc.isSelected=true; system.assertNotEquals(NULL,FsA.SubmitSelected()); //Action page testing PageReference actionPage=Page.FastSubmitActionMultiplePage ; Test.setCurrentPageReference(actionPage); ApexPages.CurrentPage().getParameters().put('allids',cc.Kase.id); FastSubmitActionClass action=new FastSubmitActionClass(); system.assertNotEquals(NULL,action.YesMulti()); system.assertNotEquals(NULL,action.NoMulti()); } //Product_udpate and OpportunityLine Item testing @IsTest Public static void AdditionalTesting(){ Product2 prod=[Select Id,Name from Product2 LIMIT 1]; prod.Name='Name Changing'; update prod; OpportunityLineItem oli=[SELECT id,PriceBookEntryId FROM OpportunityLineItem LIMIT 1]; UPDATE Oli; } }
FastSubmitAssetsClassTest.AdditionalTesting() Class 51 1 Failure Message: "System.QueryException: List has no rows for assignment to SObject", Failure Stack Trace: "Class.FastSubmitAssetsClassTest.AdditionalTesting: line 51, column 1"
Could you please post you controller..
Thanks
The error is because of you have written a query in the class and u entered the record in the test class which is not satisfing the condition of the query so it's not retreving the records into the list . Check that
Thanks,
pradeep.