1

I am trying to update some older test code to remove seeallData=true. I am getting a page error testing a quote controller extension that creates a new quote.

System.AssertException: Assertion Failed: No error message must be displayed(ApexPages.Message["Quoting cannot proceed with missing or inactive Pricing Type/Pricebook."]): Expected: true, Actual: false

Here are snippets of the code which mostly I inherited and am working to clean-up :-)

Opportunity was created in a setup method using the standard pricebook id.

quote = new Quote(Name='test quote', OpportunityId=opp.Id, pricebook2id=Test.getStandardPricebookId());
Test.startTest();
        Test.setCurrentPageReference(Page.NewQuote);
        ApexPages.currentPage().getParameters().put('oppId', opp.Id);      
        stdCont = new ApexPages.Standardcontroller(quote);
        contExt = new NewQuoteQuoteContExt(stdCont);
Test.stopTest();    
        System.assertEquals(true, contExt.isValid, 'No error message must be displayed' +  Apexpages.getMessages());
  • (1) +1 for getting rid of seeAllData=true; would everyone at SFSE be so good. (2) The error message might be a custom message that your code or Validation rule generates as 'Pricing Type' is not a SFDC concept AFAIK. Perhaps something else (custom setting, custom object row) needs mocking that seeAllData=false exposed (3) Eric has a worthwhile idea too – cropredy Dec 9 '15 at 1:25
  • Thanks crop1645! good suggestions - I did check for Vrules - but will look closer. what seems odd to me is that in general you can create quotes without a pricebook in cases where the parent opp does not yet have products so no pricebook. Also the developer who built this test seems to have created a VF page just for the test which is not used elsewhere - this doesn't seem like a best-practice to me but I am not well versed with VF/Controllers more experienced with Apex trigger code and batch Apex... – debraSF Dec 9 '15 at 16:07
  • @debraSF the vf thing is odd – Eric Dec 9 '15 at 16:10
  • Did you scan the source code and metadata to look for the message string 'Pricing Type/Pricebook' ? – cropredy Dec 9 '15 at 17:06
0

Maybe the Standard Pricebook inactive?

if so try adding this to the testSetup or beginning of your test method or where you set up the data:

PriceBook2 stdPb = New PriceBook2(id=test.getStandardPriceBookID(), isActive = true);
update stdPb;
| improve this answer | |
  • thanks Eric. I did double check the price book is active - added some debug statements to the test code. But will try your suggestion to create a pricebook explicitly for the test as this seems like a better practice anyway - not to rely on any real Org data as much as possible. – debraSF Dec 9 '15 at 16:08
0

After quite of bit of testing I was able to resolve the failing test issue with a simple change to the Test class API version - changing the API version from 27 to 35 resolved all test failures.

| improve this answer | |
  • excellent -- I'm surprised the test class even compiled if it was at V27 since Test.getStandardPricebookId() didn't show up until V31 – cropredy Dec 10 '15 at 23:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.