You need to sign in to do that
Don't have an account?
TestClass:Unable to cover formula Field
Hello guys,
i am unable to cover a opportunityLineItem formula field "product_family__c " (Formula=TEXT(PricebookEntry.Product2.Family))
in my test class. I queried the field in my controller like this :
Thanks for your time and your help!
cheers,
Sandra
i am unable to cover a opportunityLineItem formula field "product_family__c " (Formula=TEXT(PricebookEntry.Product2.Family))
in my test class. I queried the field in my controller like this :
public List <oppProduct> getOli (){ if(productList ==null){ productList = new List <oppProduct>(); for(OpportunityLineitem oli : [select Id, Quantity, Produkt__c, UnitPrice , ON_product_family__c, Product2.Name, ON_Produktbeschreibung_detailliert__c From OpportunityLineitem WHERE Opportunity.Id = :opportunityId AND ON_product_family__c = 'Extra Boost']){ productList.add(new oppProduct(oli)); } } return productList; }In my test class i created the necessary test data, but the value is always Null in the bold system.assertEquals statement
@isTest static void testGetOli () { List<CreateMultiExtraBoost.oppProduct> productListTest = new List <CreateMultiExtraBoost.oppProduct>(); Id pricebookId = Test.getStandardPricebookId(); Product2 pro = new Product2(); pro.name = 'test'; pro.Produktbeschreibung_detailliert__c = 'test'; pro.Family = 'Extra Boost'; pro.IsActive = true; insert pro; // system.assertEquals('Extra Boost', pro.Family ); Product2 pro1 = new Product2(); pro1.name = 'test'; pro1.Produktbeschreibung_detailliert__c = 'test'; pro1.Family = 'Sonstiges'; pro1.IsActive = true; insert pro1; system.assertEquals('Sonstiges', pro1.Family ); PricebookEntry pEntry = new PricebookEntry (); pEntry.Product2Id = pro.id; pEntry.UseStandardPrice = false; pEntry.UnitPrice = 600; pEntry.Pricebook2Id = pricebookId; pEntry.IsActive = true; insert pEntry; system.assertEquals(pro.id, pEntry.Product2Id); List<Product2> p = [Select Family FROM Product2 WHERE isActive=true]; List<PricebookEntry> pe = [Select Product2.Family FROM PricebookEntry]; system.assertEquals('01sD0000000hbEh', pEntry.Pricebook2Id ); system.assertEquals('Extra Boost', pEntry.Product2.Family); PricebookEntry pEntry1 = new PricebookEntry (); pEntry1.Product2Id = pro1.id; pEntry1.UseStandardPrice = false; pEntry1.UnitPrice = 300; pEntry1.Pricebook2Id = pricebookId; pEntry1.IsActive = true; insert pEntry1; Opportunity opp = new Opportunity (); opp.name = 'test'; opp.StageName = '40 - Demo Termin vereinbart'; opp.Override_Region__c = 'München'; opp.CloseDate = System.today(); insert opp; OpportunityLineItem oli = new OpportunityLineItem (); oli.TotalPrice = 500; oli.Quantity = 4; oli.OpportunityId = opp.Id; oli.Product2Id = pro.id; oli.ON_Produktbeschreibung_detailliert__c = 'test'; oli.PricebookEntryId = pEntry.id; insert oli; system.assertEquals(4,oli.Quantity ); system.assertEquals(pro.id,oli.Product2Id ); system.assertEquals(pEntry.id,oli.PricebookEntryId ); system.assertEquals(opp.Id,oli.OpportunityId ); system.assertEquals('Extra Boost', oli.ON_product_family__c); OpportunityLineItem oli1 = new OpportunityLineItem (); oli1.TotalPrice = 500; oli1.Quantity = 4; oli1.OpportunityId = opp.Id; oli1.ON_Produktbeschreibung_detailliert__c = 'test'; oli1.Product2Id = pro1.id; oli1.PricebookEntryId = pEntry1.id; insert oli1; update opp; CreateMultiExtraBoost cme = new CreateMultiExtraBoost(); if (productListTest == Null){ for(OpportunityLineitem olip : [select Id, Quantity, Produkt__c, UnitPrice , ON_product_family__c, Product2.Name, ON_Produktbeschreibung_detailliert__c From OpportunityLineitem WHERE Opportunity.Id = :opp.Id AND ON_product_family__c = 'Extra Boost']){ productListTest.add(new CreateMultiExtraBoost.oppProduct(olip)); } } cme.getOli(); }I inserted the records and queried them, but unfortunately it doesen't work.
Thanks for your time and your help!
cheers,
Sandra