0

VF Page

<apex:inputField value="{!Opportunity.Start_Date__c}" />
           <apex:selectList value="{!Opportunity.Customer_Group_ERP__c}" id="customer" size="1" multiselect="false" required="true">
                 <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:actionSupport event="onchange" reRender="C"/>

                  </apex:selectList> 

          <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:selectList value="{!Opportunity.Node_Size__c}" size="1" multiselect="false" id="D">
              <apex:selectOptions value="{!Node}" />                  
                   </apex:selectList>  

Controller

public class CreateOppExtension 
{

    Opportunity opp {get;set;}
    String Owner {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> getNode()
       {


           List<SelectOption> reason = new List<SelectOption>();
           reason.add(new SelectOption('None','--None--'));
           Schema.DescribeFieldResult Rea = Opportunity.Reason_PM_I__c.getDescribe();
           List<Schema.PicklistEntry> R = Rea.getPicklistValues();
           for(Schema.PicklistEntry Q : R)
               reason.add(new SelectOption(Q.getLabel(), Q.getValue())); 
           return reason;


       }
2
  • Why don't you convert the field Customer_Group_ERP__c to picklist on the Opportunity object and make it required. Then using apex:inputField will do the trick for you.
    – Kevan
    Jun 22 '17 at 14:33
  • @Kevan there are different record types on Opportunites which does not want the field as required..There are other picklist fields which needs to be required :(
    – User 7864
    Jun 22 '17 at 14:45
1

In the line:

<apex:selectOption itemValue="None" itemLabel="--None--"/>  

Just remove the itemValue parameter, or set it to null/empty.

<apex:selectOption itemValue="" itemLabel="--None--"/>

Setting required="true" as a <apex:selectList> parameter should throw an error then.

For example, using the below code:

<apex:page showHeader="true" sidebar="true">
    <apex:pageMessages id="errors" />
    <apex:form>
        <apex:selectList id="customer" size="1" multiselect="false" required="true">
            <apex:selectOption itemValue="" 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:actionSupport event="onchange" reRender="C"/>
        </apex:selectList> 
        <apex:commandButton value="Submit" reRender="errors" />
    </apex:form>
</apex:page>

Throws the following:

enter image description here

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.