• juniorj
  • 0 Points
  • Member since 2009

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
  • 0

Hi there. I have written a controller extension that works a charm.

In one of my methods (that is invoked from the constructor when the page loads),

I do a getDescribe() to get the picklist values for a field. Nothing strange so far... 



//mandatory controller extension constructor... public StockOrderPageExtension(ApexPages.StandardController stdController) { this.contextStockOrder = (Stock_Order__c) stdController.getRecord(); queryForProductCategories(); showSaveMessage = false; } //This method queries for all the current Bausch product Categories... public void queryForProductCategories() { //Get the Field Token Schema.SObjectField sf = Stock_Product__c.Product_Type__c; //Call describe on the Field Token Schema.DescribeFieldResult sdfr = sf.getDescribe(); //add the defaul sf selectlist value to //the SelectOption list... allProductCategories.add(new SelectOption('null','--None--')); for( Schema.PicklistEntry plentry : sdfr.getPicklistValues()) allProductCategories.add(new SelectOption(plentry.getValue(),plentry.getLabel())); }

Ok. So....

In my test method I have created 1 dummy Stock_Product__c records and given it a Product_Type__c value.



//Create some Product Categories Stock_Product__c stockProduct = new Stock_Product__c(name='mac', Product_Type__c='Notebook');


Fine. So..... 

Now I create an instance of my controller extension.

This invokes the method queryForProductCategories().

I then do a System.debug() on the allProductCategories List in my test method (which is a list of SelectOptions)


System.debug('****** ALL PRODUCT CATEGORIES ARE: ' + extensionController.getAllProductCategories());


I do not see the stock product I created in my test method above.

How on earth can I get around this? I really cannot see a path.

It makes sense in one degree that when teh method queryForProductCategories is invoked (from the test class),

it will get all the picklist values that are committed to the database. 

Has anyone got any help or suggestions? Greatly appreciated.