0
Account testAccount=new Account(Name='TestAccountForTestClass',ShippingCountry='India',RecordTypeId=recordId1);                                    
           Insert testAccount;

           Id pricebookId = Test.getStandardPricebookId();

           Opportunity objOpportunity = TestingSetupDataUtil.createOpportunity(testAccount.Id, 'test Oppty',system.today()+30);
           objOpportunity.Route_To_Market__c = 'Direct';
           objOpportunity.Customer_Engagement__c = 'End User Sales';
           objOpportunity.Fulfillment__c = 'HP Fulfilled';
           objOpportunity.ForecastCategoryName = 'Pipeline';
           objOpportunity.Managed_By__c='HP';
           objOpportunity.stagename = '02 - Validate Opportunity';
           objOpportunity.Pricebook2id = pricebookId;

           Test.startTest();
           insert objOpportunity;
           System.Debug('----Opportunity---'+objOpportunity);

           Product2 prodObj = TestingSetupDataUtil.createProduct(true,'testprod','USD','Test');
           insert prodObj;

           PricebookEntry customPrice = new PricebookEntry(Pricebook2Id = pricebookId, Product2Id = prodObj.Id,UnitPrice = 12000, IsActive = true);
           insert customPrice;

           date dt = date.today()+400;
           OpportunityLineItem oliObj = TestingSetupDataUtil.createOpportunityLineItem(2.0,15,99,objOpportunity.id,customPrice.id, dt);
           insert oliObj;

           objOpportunity.stagename = '04A - Develop Solution';
           update objOpportunity;
2
  • getting error "pricebook entry is in a different pricebook than the one assigned to the opportunity" on insert OliObj;
    – happy
    Commented Nov 27, 2015 at 7:17
  • (1) are you sure your test factory is properly building the OLI? (2) No trigger or workflow on Opportunity that nulls out pricebook2Id?
    – cropredy
    Commented Nov 27, 2015 at 15:46

0

You must log in to answer this question.

Browse other questions tagged .