function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Newbie  2014Newbie 2014 

Help requested to debug a test class

Hi: I wrote this simple test class below hardcoding with a id. I executed the select statments in query editor, returning 8 ids correctly. But when run the test class below and check logs, I see it is gettign 0 rows after execution. Can't figure out why that might happen. Any clue will be appreciate. Much thanks

--------
@isTest()
public class deleleteLineItem
{
static testmethod void unittest() {
   
List<opportunitylineitem> ol = new List<opportunitylineitem>();
ol = [select id from opportunitylineitem where opportunityid = '006m0000002IbCiAAK'] ;

for(opportunitylineitem o: ol){
delete o;}

}
}
Best Answer chosen by Newbie 2014
kevin lamkevin lam
Data in your org are not accessible to unit tests by default, you need to update @isTest() to @isTest(SeeAllData=true).

All Answers

kevin lamkevin lam
Data in your org are not accessible to unit tests by default, you need to update @isTest() to @isTest(SeeAllData=true).
This was selected as the best answer
nbknbk
You need to create test data to fulfill the select statement. for example

account a = new account(name='testacount');
insert a;
Opportunity o = new Opportunity(name='testopp', accountid=a.id);
insert o;
//u can create OpportunityLineItem and insert opprtinity Id with 0.id...etc


Newbie  2014Newbie 2014
Thank you much Kevin, that helped.