You need to sign in to do that
Don't have an account?
Sammy7
Pricebook difficulty in test class
Hi , this is my first test class and Im not getting how the ids are different in this error. All Im trying to do is create a opp, quote, quotelineitem and close the opp so my trigger fires.
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: PricebookEntryId (pricebook entry is in a different pricebook than the one assigned to the opportunity): [PricebookEntryId]
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: PricebookEntryId (pricebook entry is in a different pricebook than the one assigned to the opportunity): [PricebookEntryId]
@isTest private class CreateInvoiceTestClass { @isTest static void insertOpp() { Pricebook2 pb = new Pricebook2(Name = 'Standard Price Book 2009', Description = 'Price Book 2009 Products', IsActive = true ); insert pb; Product2 prod = new Product2(Name = 'SLA: Bronze', IsActive = true); insert prod; PricebookEntry pbe=new PricebookEntry(unitprice=0.01,Product2Id=prod.Id, Pricebook2Id=Test.getStandardPricebookId(), IsActive= true); insert pbe; Account acc = new Account (name='Acme'); insert acc; Opportunity opp= new Opportunity (); opp.name= 'Testopp'; Opp.Accountid= acc.id; opp.CloseDate= date.today(); opp.StageName= 'Qualification'; opp.Pricebook2id=pb.id; insert opp; OpportunityLineItem oppLine = new OpportunityLineItem( pricebookentryid=pbe.Id,TotalPrice=2000, Quantity = 2,Opportunityid = opp.Id); insert oppLine; Quote q= new Quote (); q.Name= 'Testq'; q.OpportunityId= Opp.id; q.quotetoinvoice__C= TRUE; q.REP__C= 'AC' ; q.BillingStreet= '123'; q.BillingCity= 'City'; q.BillingPostalCode= '12345'; q.Pricebook2Id= pb.id; insert q; QuoteLineItem qli= new QuoteLineItem(Quoteid=q.id, PricebookEntryid= pbe.Id, quantity=2, unitprice=10000); insert qli; opp.StageName= 'Closed Won'; } }
give it a try.
Let me know if it helps.
Thanks.
All Answers
give it a try.
Let me know if it helps.
Thanks.
Thats best practice.better to write utility classes.
Thanks.