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

Pricebook and PricebookEntry in TestMethod
Hi all,
I wrote a simple test class and I get an Error saying : 'PriceBookEntry is in a different PriceBook than the one assigned to the Opportunity'. (the Error is in the line saying OpportunityLineItem OppLI_Rec = new Opportunity(...);
insert OppLI_Rec;
I can't find the problem in here.
I appreciate your help.
Thanks, Assaf
I wrote a simple test class and I get an Error saying : 'PriceBookEntry is in a different PriceBook than the one assigned to the Opportunity'. (the Error is in the line saying OpportunityLineItem OppLI_Rec = new Opportunity(...);
insert OppLI_Rec;
Code:
public class Test_updateQuarterToOppProd { static testMethod void UpdateQuarter(){ //insert a new product Product2 p = new product2(name='x'); insert p; Product2 p2 = new product2(name='y'); insert p2; //define the standart price for the product Pricebook2 stdPb = [select Id from Pricebook2 where isStandard=true limit 1]; insert new PricebookEntry(pricebook2id = stdPb.id, product2id = p.id,unitprice=1.0, isActive=true); Pricebook2 pb = new pricebook2(name='test'); insert pb; PricebookEntry pbe = new PricebookEntry(pricebook2id=pb.id, product2id=p.id,unitprice=1.0, isActive=true); insert pbe; Account AcntRec = new Account(name = 'Acc', Type = 'Customer', Industry = 'Automotive'); insert AcntRec; Opportunity OppRecA = new Opportunity(AccountId = AcntRec.Id, name='Opp', stageName='Open', closeDate=Date.newInstance(2008,10,10), revenue_recognition__c = 'Q1'); insert OppRecA; OpportunityLineItem OppLI_Rec = new OpportunityLineItem(OpportunityId = OppRecA.Id, pricebookentryid=pbe.id, UnitPrice = 100, Quantity = 3); insert OppLI_Rec; OppRecA.revenue_recognition__c = 'Q2'; update OppRecA; system.assertEquals('Q2',[select Quarter__c from OpportunityLineItem where Id = :OppLI_Rec.Id].Quarter__c); } }
I can't find the problem in here.
I appreciate your help.
Thanks, Assaf
now I get an Error saying: 'System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, UpdateOpportunityWhenOplinePercentageChange: execution of AfterUpdate'
on the following line: 'insert oli';
I tried to retrieve all id necessary for the creation of an opportunityLineItem and still gets the same Error.
any ideas?
any help will be appreciated.
thanks.
Message Edited by Assaf on 09-29-2008 12:45 AM
fixed it.