1

enter image description here

I am trying to fetch picklist values in VF page.But it is displaying in wierd way.Please find the screenshot.

VF Page:

<apex:page standardController="Opportunity" extensions="CreateOppExtension">
  <apex:form >
    <apex:pageBlock title="Opportunity Edit" mode="save">
      <apex:pageBlockButtons >
        <apex:commandButton action="{!save}" value="Save" />
        <apex:commandButton action="{!cancel}" value="Cancel"/>
      </apex:pageBlockButtons>

      <apex:pageBlockSection title="Opportunity Information" columns="2">
          <apex:inputField value="{!Opportunity.Name}"/>
          <apex:inputField value="{!Opportunity.Opportunity_Type__c}"/>
          <apex:inputField value="{!Opportunity.Start_Date__c}"/>
          <apex:inputField value="{!Opportunity.CloseDate}"/>

          <apex:selectList value="{!Opportunity.PM_I_Business_Field__c}" size="1" style="width:400px" >
              <apex:selectOptions value="{!TypeOptions}"/>                  

                            </apex:selectList> 

          <apex:inputField value="{!Opportunity.Main_Group_GPH1__c}"/>

          <apex:inputField value="{!Opportunity.Product__c}"/>
          <apex:inputField value="{!Opportunity.USP__c}"/>


          <apex:selectList value="{!Opportunity.Process_Quadrant__c}" multiselect="false" size="1">
               <apex:selectOption itemValue="None" itemLabel="--None--"/>
                <apex:selectOption itemValue="Protect Base/Manage Needs" itemLabel="Protect Base/Manage Needs"/>
                <apex:selectOption itemValue="Grow Share/New Products" itemLabel="Grow Share/New Products"/>
                <apex:selectOption itemValue="Replace Competitors/Deliver Unmet Needs" itemLabel="Replace Competitors/Deliver Unmet Needs"/>
                <apex:selectOption itemValue="New Markets/What-If Innovation" itemLabel="New Markets/What-If Innovation"/>
          </apex:selectList>

            <apex:selectList value="{!Opportunity.Customer_Group_ERP__c}" id="customer" size="1" multiselect="false">
                 <apex:selectOption itemValue="None" itemLabel="--None--"/>   
                <apex:selectOption itemValue="SAMSUNG" itemLabel="SAMSUNG"/>    
                 <apex:selectOption itemValue="SAE MAGNETICS" itemLabel="SAE MAGNETICS"/>    
                 <apex:selectOption itemValue="MICRON GROUP" itemLabel="MICRON GROUP"/>    
                 <apex:selectOption itemValue="TOSHIBA" itemLabel="TOSHIBA"/>    
                 <apex:selectOption itemValue="TSMC" itemLabel="TSMC"/>    
                 <apex:selectOption itemValue="INTEL" itemLabel="INTEL"/>     
                 <apex:selectOption itemValue="GLOBALFOUNDRIES" itemLabel="GLOBALFOUNDRIES"/>    
                   <apex:selectOption itemValue="NANYA" itemLabel="NANYA"/> 
                 <apex:selectOption itemValue="POWERCHIP" itemLabel="POWERCHIP"/>    
                 <apex:selectOption itemValue="WINBOND" itemLabel="WINBOND"/>    
                 <apex:selectOption itemValue="UMC" itemLabel="UMC"/>   
                  <apex:selectOption itemValue="Others" itemLabel="Others"/>  
                  </apex:selectList> 

            <apex:selectList value="{!Opportunity.Device__c}">
              <apex:selectOptions value="{!TypeCG}"/>                  
                   </apex:selectList>  




          <apex:inputField value="{!Opportunity.TopProject__c}"/>

            </apex:pageBlockSection>
            <apex:pageBlockSection title="References" columns="2">
                <apex:inputField value="{!Opportunity.Master_Account__c}"/>
                <apex:inputField value="{!Opportunity.R_D_Project__c}"/>
                <apex:inputField value="{!Opportunity.Project_ID__c}"/>
                <apex:inputField value="{!Opportunity.NBD_ID__c}"/>                        
             </apex:pageBlockSection>

                <apex:pageBlockSection title="Sales Cycle" columns="2">
                    <apex:inputField value="{!Opportunity.StageName}"/>
                    <apex:inputField value="{!Opportunity.Status__c}"/>

               <apex:selectList value="{!Opportunity.Reason_PM_I__c}" multiselect="false" size="1">
               <apex:selectOption itemValue="None" itemLabel="--None--"/>
                <apex:selectOption itemValue="Quality" itemLabel="Quality"/>
                <apex:selectOption itemValue="Service" itemLabel="Service"/>
                <apex:selectOption itemValue="Price" itemLabel="Price"/>
                <apex:selectOption itemValue="Other" itemLabel="Other"/>
          </apex:selectList>
                    <apex:selectList value="{!Opportunity.Sub_Reason__c}"> 
                      <apex:selectOptions value="{!subreason}"/>
          </apex:selectList>

                    <apex:inputField value="{!Opportunity.Probability}"/>
                    <apex:inputField value="{!Opportunity.Exp_Sales_Vol_p_a_EUR__c}"/>  
                    <apex:inputField value="{!Opportunity.Expected_Rev_rHVM__c}"/>
                    <apex:inputField value="{!Opportunity.PMI_In_Forecast__c}"/>

                   <apex:selectList value="{!Opportunity.Main_Group_GPH1__c}">
              <apex:selectOptions value="{!TypeDevice}"/>                  
                   </apex:selectList> 

                    <apex:inputField value="{!Opportunity.Counter_Measures__c}"/>
                    <apex:inputField value="{!Opportunity.Price_EUR_Unit__c}"/>
                    <apex:inputField value="{!Opportunity.Dispense_Volume_mUnit__c}"/>
                    <apex:inputField value="{!Opportunity.Layers__c}"/>
                    <apex:inputField value="{!Opportunity.Unit__c}"/>
                    <apex:inputField value="{!Opportunity.R_D_Headcount__c}"/>
        </apex:pageBlockSection>
                     <apex:pageBlockSection title="Notes" columns="1">
          <apex:inputField value="{!Opportunity.Notes__c}"/>
          <apex:inputField value="{!Opportunity.Marketing_Notes__c}"/>
      </apex:pageBlockSection>

    </apex:pageBlock>
  </apex:form>
</apex:page>

Apex controller:

public class CreateOppExtension 
{

    Opportunity opp {get;set;}
    ApexPages.StandardController GstdController;
     public CreateOppExtension(ApexPages.StandardController stdController)
     {   
        GstdController= stdController;
        opp = (Opportunity)stdController.getRecord();
        opp.Notes__c = 'Testing';
    }

       public List<SelectOption> getTypeOptions()
       {


           List<SelectOption> options = new List<SelectOption>();
           options.add(new SelectOption('None','--None--'));
           Schema.DescribeFieldResult fieldResult = Opportunity.PM_I_Business_Field__c.getDescribe();
           List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
           for(Schema.PicklistEntry p : ple)
               options.add(new SelectOption(p.getLabel(), p.getValue())); 
           return options;


       }
     public List<SelectOption> getsubreason()
       {


           List<SelectOption> reasons = new List<SelectOption>();
           reasons.add(new SelectOption('None','--None--'));
           Schema.DescribeFieldResult sub = Opportunity.Sub_Reason__c.getDescribe();
           List<Schema.PicklistEntry> reason = sub.getPicklistValues();
           for(Schema.PicklistEntry S : reason)
               reasons.add(new SelectOption(S.getLabel(), S.getValue())); 
           return reasons;


       }
       public List<SelectOption> getTypeCG()
       {
           List<SelectOption> cglist = new List<SelectOption>();
           cglist.add(new SelectOption('None','--None--'));
           Schema.DescribeFieldResult f = Opportunity.Device__c.getDescribe();
           List<Schema.PicklistEntry> pick = f.getPicklistValues();
           for(Schema.PicklistEntry b: pick)
               cglist.add(new SelectOption(b.getLabel(), b.getValue())); 
           return cglist;
     }

     public List<SelectOption> getTypeDevice()
       {
            List<SelectOption> dev = new List<SelectOption>();
           dev.add(new SelectOption('None','--None--'));
           Schema.DescribeFieldResult d = Opportunity.Main_Group_GPH1__c.getDescribe();
           List<Schema.PicklistEntry> pick = d.getPicklistValues();
           for(Schema.PicklistEntry J: pick)
               dev.add(new SelectOption(J.getLabel(), J.getValue())); 
           return dev;
     }


     public PageReference save(){
        insert opp;
        return ApexPages.currentPage();

    }

}
0

In order to display only one value of picklist use size="1". To disable multi-select add multiselect="false"

<apex:selectList value="{!Opportunity.Sub_Reason__c}" multiselect="false" size="1> 
    <apex:selectOptions value="{!subreason}"/>
</apex:selectList>
1
  • Thank you @ Alexander Berehovskiy It worked,But there are field dependencies between Reason --> Subreason ,Customer group ERP and Device picklist values. I have fetched these values dynamically. Field Dependency is NOT working in this VF page.Please help
    – User 7864
    Jun 22 '17 at 11:26

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.