• cloudjedi1.3940876426809475E12
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
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;

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



  • September 28, 2008
  • Like
  • 0