• Steve Cap
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

I'm writing a unit test on the opportunity and opportunity line item.  I am getting the error "No standard price is defined".

 

Here is my test method:

 

public static testMethod void test3() 
    { 
    	Pricebook2 pb = new Pricebook2(Name = 'Standard Price Book 2009', Description = 'Price Book 2009 Products', IsActive = true);
    	insert pb;
    	Product2 prod = new Product2(Name = 'Anti-infectives 2007', Family = 'Best Practices', Practice__c = 'GP/BP', Service_Level__c = 'Partial Service', Product_Abbrev__c = 'CMR_Antiinfect', Sales_Unit__c = 'Each', Standard_Unit__c = 'Each', Product_Year__c = '07', Item_Type__c = 'Non-Inventory (Sales only)', IsActive = true);
    	insert prod;
    	PricebookEntry pbe = new PricebookEntry(Pricebook2Id = pb.Id, Product2Id = prod.Id, UnitPrice = 10000, IsActive = true, UseStandardPrice = false);
    	insert pbe;
    	Opportunity opp = new Opportunity(Name = 'Test Syndicated 2010', Type = 'Syndicated - New', StageName = 'Planning', CloseDate = system.today());
    	insert opp;
    	OpportunityLineItem oli = new OpportunityLineItem(opportunityId = opp.Id, pricebookentryId = pbe.Id, Quantity = 1, UnitPrice = 7500, Description = '2007 CMR #4 - Anti-Infectives');
    	insert oli;
		List<OpportunityLineItem> olis = [Select Id From OpportunityLineItem Where OpportunityId =: opp.Id];
		update olis[0];
    }

 

The error is thrown on the line where I try and insert the PricebookEntry record:

 

PricebookEntry pbe = new PricebookEntry(Pricebook2Id = pb.Id, Product2Id = prod.Id, UnitPrice = 10000, IsActive = true, UseStandardPrice = false);
    	insert pbe;

 

I'm not sure what I'm missing. 

 

Thanks for any help.

Regards.