1

VF Page:

<apex:page standardController="Order__c" extensions="MyOrderPadController" >   
     <apex:detail />
        <apex:form > 
        <apex:pageBlock >
            <apex:pageBlockButtons > 
                <apex:commandButton action="{!save}" value="Save"/>
                <apex:commandButton action="{!edit}" value="Edit"/>
                <apex:commandButton action="{!reset}" value="Cancel" />
            </apex:pageBlockButtons>   
            <apex:pageBlockSection columns="2" title="Order Pad">
            <apex:inputField value="{!Order__c.Order_Description__c}"  />        
                    <apex:inputField value="{!Order__c.Creat_Date__c}"  />
                    <apex:inputField value="{!Order__c.Closed_Date__c}"  />
                     <apex:inputField value="{!Order__c.Conformation__c}"  />  
                      <apex:inputField value="{!Order__c.User_Description__c}" />
                       <apex:selectList id="bidpro"  size="1" >
                   <b>  Bid Pro &nbsp; </b><apex:selectOptions value="{!bidpro}"></apex:selectOptions>
</apex:selectList>                   
            </apex:pageBlockSection>
        </apex:pageBlock>    
    </apex:form>   
</apex:page>

Controller:MyOrderPadController

public class MyOrderPadController {
    public Order__c order{ get; private set; }
     List<selectOption> options = new List<selectOption>(); 
     public List<selectOption> getbidpro() 
     {

      options.add(new selectOption('', '- None -')); 
      options.add(new selectOption('a', 'A')); 
      options.add(new selectOption('b', 'B')); 
      options.add(new selectOption('c', 'C')); 
      return options; 

      }



    NewAndExistingController  test = new NewAndExistingController ();

        public MyOrderPadController ()
       {

       }
    public MyOrderPadController(ApexPages.StandardController sc) {

        order = (Order__c)sc.getRecord();
        order.Order_Description__c = ApexPages.currentPage().getParameters().get('bidpro')+':'+options;
        order.Account__c = ApexPages.currentPage().getParameters().get('aid');  
    }
public PageReference edit() 
     { 
           return null;        
     }
     public PageReference reset()
     {
          PageReference newpage = new PageReference(System.currentPageReference().getURL());

          newpage.setRedirect(true);
          return newpage;
    }
     public PageReference save() 
     {
          TRY
          {              
               order.Name = 'Demo Test Order '+order.Order_Description__c;
               order.Order_Description__c =''';**//set the selected pick list option here**                              IF(order.Conformation__c == TRUE){


                    INSERT order; 
                    PageReference newpage = new PageReference(System.currentPageReference().getURL());
                    newpage.setRedirect(true);
                    return newpage;     
                    }


                    }   

          catch(System.DMLException e) 
          {
            ApexPages.addMessages(e);
            SYSTEM.DEBUG('ERROR ORDER PAD CONTROLLER :'+e);
            return null;
          }

        return null;        
     }   
}

I am unable to get the selected pick list value in the controller.The VF page contains custom object fields and one dynamic pick list.

5

Replace the code in page

<apex:selectList value="{!bidpro}" size="1" rendered="true">
          <apex:selectOptions value="{!selectedOptionValue}">         
          </apex:selectOptions>     
      </apex:selectList>  

and get set the value in controller like

public string selectedOptionValue{get;set;}

and use it up wherever u want in controller.

  • see the bellow link also salesforce.stackexchange.com/questions/21847/… – Sunny Dec 24 '13 at 7:19
  • I ran into an issue with this code. It complains that selectList value should be read only, so I cannot modify it in getBidPro method. How can I get around this to populate values for the selectList? Thanks. – user19076 Apr 27 '15 at 21:04

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.