function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
djbakerman.ax666djbakerman.ax666 

problem with describe custom object picklist

Hello -

 

I'm trying to use a custom controller to display a picklist of a custom object. The below code works when I place it in anonymous, but fails when I upload the class. Maybe I need a test class?

 

public with sharing class ebsController{

    public List<SelectOption> getDatacenter()
    {  
           List<SelectOption> options = new List<SelectOption>();        
           Schema.DescribeFieldResult fieldResult = Pod_UPS__c.Datacenters__c.getDescribe();
           List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();    
           
           options.add(new SelectOption('','--Select Data Center --'));
        
           for( Schema.PicklistEntry f : ple)
           {
              options.add(new SelectOption(f.getLabel(), f.getValue()));
              System.debug(logginglevel.INFO,f.getLabel() + ',' + f.getValue());
           }
               
           return options;
    }
}

 

 

Thanks, Daniel

Best Answer chosen by Admin (Salesforce Developers) 
kwukwu

When you deploy files from sandbox to production, make sure you are only deploying exactly the files you want to deploy. Sometimes the IDE thinks you are trying to deploy a bunch of files which maybe you never intended to deploy. This will bring down your overall code coverage.

 

When you deploy, click "validate deployment" and make sure everything is good to go. It will tell you which files are not properly code covered.

All Answers

kwukwu

What error message are you getting?

mtbclimbermtbclimber

You do know that you can do this too, right?

 

 

<apex:inputField value="{!Pod_UPS__c.Datacenters__c}"/>

 

I presume you are doing the below because you want to add the default option with the specified text. Just want to make sure you and future readers know there is an easier way to get the standard behavior. :)

djbakerman.ax666djbakerman.ax666

Kevin -

 

I get no obvious error message (using eclipse IDE) but some warnings about test is 68% and not 75%. 

 

-Dan

djbakerman.ax666djbakerman.ax666

Andrew -

 

I've tried that out and it always returns blank values.  I've ensured I have some entries in that picklist, but it returns blanks.  I thought I would need to do a describe to pull the field values out of the picklist.

 

-Daniel

mtbclimbermtbclimber

Can you post a sample page (with the minimum amount of tags) that reproduces this issue?  I've not heard this before and would like to investigate.

 

Thanks,

djbakerman.ax666djbakerman.ax666

I've tried two versions, one using standard controller (yields blank) and also the custom controller, which won't let me save to server.

 

Standard Controller:

<apex:page standardController="Pod_UPS__c" >
<apex:form >
        <apex:pageBlock title="EBS" mode="edit">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="POD LOCATION" columns="2">
                <apex:selectList value="{!Pod_UPS__c.Datacenters__c}" size="5" >
                    <apex:actionSupport event="onchange" rerender="list"/>
                    <apex:selectOptions value="{!Pod_UPS__c.Datacenters__c}"/>
                </apex:selectList>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

Custom Controller:

<apex:page controller="ebsController" standardStylesheets="false" showHeader="false" sidebar="false">
  <h1>Welcome to the Emergency Broadcast System (EBS)</h1>
  <apex:form >
<apex:outputLabel value="Please select from the following options:" />
<apex:selectList value="{!MyPicklistvalue}" size="1">
<apex:selectOptions value="{!datacenter}"/>
</apex:selectList>
<apex:commandButton value="Go Home" action="{!DCSelector}" rerender="dcselected"/>
</apex:form>
</apex:page>

 

Thank you,

 

Dan

djbakerman.ax666djbakerman.ax666

 


djbakerman wrote:

Kevin -

 

I get no obvious error message (using eclipse IDE) but some warnings about test is 68% and not 75%. 

 

-Dan


Kevin - I should clarify, the IDE gives me no error but it won't save the code to the server, only saves local copy.

 

kwukwu

When you deploy files from sandbox to production, make sure you are only deploying exactly the files you want to deploy. Sometimes the IDE thinks you are trying to deploy a bunch of files which maybe you never intended to deploy. This will bring down your overall code coverage.

 

When you deploy, click "validate deployment" and make sure everything is good to go. It will tell you which files are not properly code covered.

This was selected as the best answer
djbakerman.ax666djbakerman.ax666

Aha, so it seems to be a firefox on win7 issue.  I have tried both of my above codes at home with Safari and Mac Os X, runs fine.  Thanks all!

 

-Dan