You need to sign in to do that
Don't have an account?

PriceBookEntry records in Apex Test Class
Hi,
I am using the following snippet in a Test Class. When I copy it in Developer Console, it works just fine ! But in the test class, the size of pbe list is zero !
Thanks !
I am using the following snippet in a Test Class. When I copy it in Developer Console, it works just fine ! But in the test class, the size of pbe list is zero !
List<PriceBookEntry> pbe = new List<PriceBookEntry>( ); pbe = [Select Id,Name,PriceBook2ID, Product2Id from PriceBookEntry where ProductCode = 'NRG-HF-89-C0' and CURRENCYISOCODE='USD']; System.Debug(pbe.size()); Opportunity o= new Opportunity(Name = 'Test Opportunity', StageName = 'Drop In', CloseDate = system.today() + 30); insert o; Quote q= new Quote(Name = 'Test Quote', Status = 'Draft', OpportunityId = o.Id, Pricebook2Id=pbe[0].PriceBook2Id); insert q; QuoteLineItem qli= new QuoteLineItem (Quantity=1, QuoteId=q.Id,UnitPrice=100.00, Discount = 50, PriceBookEntryId = pbe[0].Id, Product2Id=pbe[0].Product2Id); insert qli; System.assertNotEquals(null,q); // Retrieve the create quote line item qli = [SELECT Id,TotalPrice,Discount,Discount_Amount__c FROM QuoteLineItem WHERE Id =:qli.Id]; System.assertEquals(50,qli.Discount_Amount__c); qli.Discount = 25; update qli; // Retrieve the create quote line item qli = [SELECT Id,TotalPrice,Discount,Discount_Amount__c FROM QuoteLineItem WHERE Id =:qli.Id]; System.assertEquals(25,qli.Discount_Amount__c); delete o;
Thanks !
All Answers