+ Start a Discussion
catchforshivacatchforshiva 

How to display the Text Field values using Picklist values when you are submite the commad button?

Hi,


I was created " Bike Sells" customer object.
In this object i was created three fields.


1. Bike Model: Datatype (picklist)
2. Customer: Name datatype (Text)
3. Cost: datatype(Number)

My requirement is when i was select the 'Bike model' picklist values
click to submite the command button,i want to dispaly
the Customer Name, Cost  and Date Details of the paticuler Bike model piclist value.

 

Example: I select Picklist value: AUDI,It displays Audi car related customer Name and Cost.

 

How to find this problem?

 

 

 

 

 

 Code:


Visualforce:

 

<apex:page standardController="Car_Sells__c" recordSetVar="cs" extensions="stateExtension" sidebar="false">
    <apex:form >
        <apex:sectionHeader title="Car Sells Details"/>
        <apex:pageBlock title="Car Sells" mode="edit">
            <apex:pageBlockSection columns="1" showHeader="false">
                <apex:panelGroup >
                     <apex:outputLabel value="Select Car Model" for="accts" rendered="true"></apex:outputLabel>&nbsp;&nbsp;&nbsp;&nbsp;
                            <apex:selectList id="accts" value="{!Car_Sells__c.Car_Model__c}" size="1" title="Select State">
                                <apex:selectOptions value="{!accts}"></apex:selectOptions>
                            </apex:selectList>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                   <apex:commandButton action="{!doSearch}" value=" Show Customer Details" > </apex:commandButton>                    
                </apex:panelGroup>
            </apex:pageBlockSection><br/><br/><br/>
<apex:pageBlocksection colums="1" id="results">
<apex:pageBlockTable value="{!results}" var="item">
<apex:column value="{!item.Name}"/>
<apex:column value="{!item.Cost__c}"/>
<apex:column value="{!item.Date__c}"/>
</apex:pageBlockTable>
</apex:pageBlocksection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Apex code:

 

public class stateExtension {
    String accts;
   
    private final Car_Sells__c c; //User sobject
    
    //initializes the private member variable u by using the getRecord method from the standard controller
    
    public stateExtension(ApexPages.StandardSetController Controller) {
    
        this.c = (Car_Sells__c)Controller.getRecord();

    }
    
    //builds a picklist of Car_Sells__c  names based on their Car_Model__c
    public List<selectOption> getaccts() {

        List<selectOption> options = new List<selectOption>();
//new list for holding all of the picklist options
        options.add(new selectOption('', '- None -'));
//add the first option of '- None -' in case the user doesn't want to select a value or in case no values are returned from query below
        for (Car_Sells__c m : [SELECT Id, Name, Car_Model__c, Date__c FROM Car_Sells__c]) {
//query for Car_Sells__c records
            options.add(new selectOption(m.id, m.Car_Model__c));
//for all records found - add them to the picklist options
        }
        return options; //return the picklist options
    }

List<Car_Sells__c> mktsys;
   public void setAccts(String s) {
      accts =s;
   }
   public List<Car_Sells__c> getMktsys() {
      return mktsys;
   }
   public PageReference doSearch() {
      // Search by Exactly word
     mktsys = (List<Car_Sells__c>)[SELECT Id, Name, Cost__c FROM Car_Sells__c WHERE Car_Model__c =:accts];
 
       String qryString = 'SELECT Id, Name, Cost__c FROM Car_Sells__c WHERE Car_Model__c = :accts';
     mktsys = Database.query(qryString);
      return null;
   }

}

 

 

 

 

 

 

 

 

Thanks & Regards

SHIVA

 

 

 

 

 

 

 

 

 

 

 

 

 

lovetolearnlovetolearn

Hi, 

 

I think the problem is with your setter method. The variable 'accts' is not passing any values into your controller. Try a system debug in your doSearch method. 

 

I change things around a bit for you in order to pass the value of "accts" into your controller. Try this out:

 

VF page: 

 

<apex:page standardController="Car_Sells__c" recordSetVar="cs" extensions="stateExtension" sidebar="false">
     <script type='text/javascript'>
        function copyAccts(){
            document.getElementById('{!$Component.car.carPB.hiddenAccts}').value = document.getElementById('{!$Component.car.carPB.carPBS.accts}').value;
        }
    </script>
    <apex:form id="car">
  
        <apex:sectionHeader title="Car Sells Details"/>
        <apex:pageBlock title="Car Sells" mode="edit" id="carPB">
            <apex:pageBlockSection columns="1" id="carPBS">
                <apex:panelGroup id="carPG">
                     <apex:outputLabel value="Select Car Model" for="accts"></apex:outputLabel>&nbsp;&nbsp;&nbsp;&nbsp;
                            <apex:selectList id="accts" value="{!Car_Sells__c.Car_Model__c}" size="1" title="Select State" onchange="copyAccts()">
                                <apex:selectOptions value="{!accts}"></apex:selectOptions>
                            </apex:selectList>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                   <apex:commandButton action="{!doSearch}" value=" Show Customer Details" reRender="results"> </apex:commandButton>                    
                </apex:panelGroup>
            </apex:pageBlockSection><br/><br/><br/>
            
            
            <apex:pageBlocksection columns="1" id="results">
                <apex:pageBlockTable var="item" id="resultTable" value="{!mktsys}">
                    <apex:column value="{!item.Name}"/>
                    <apex:column value="{!item.Cost__c}"/>
                    <apex:column value="{!item.Date__c}"/>
                </apex:pageBlockTable>
            </apex:pageBlocksection>
            
            <apex:inputHidden id="hiddenAccts" value="{!hiddenAccts}"/>
        </apex:pageBlock>
    
    </apex:form>
</apex:page>

 

Controller:

 

public class stateExtension {
    
    String accts;
    public string hiddenAccts {get; set;}
   
    private final Car_Sells__c c; //User sobject
    
    //initializes the private member variable u by using the getRecord method from the standard controller
    
    public stateExtension(ApexPages.StandardSetController Controller) {
    
        this.c = (Car_Sells__c)Controller.getRecord();

    }
    
    //builds a picklist of Car_Sells__c  names based on their Car_Model__c
    public List<selectOption> getaccts() {

        List<selectOption> options = new List<selectOption>();
        //new list for holding all of the picklist options
        options.add(new selectOption('', '- None -'));
        //add the first option of '- None -' in case the user doesn't want to select a value or in case no values are returned from query below
        for (Car_Sells__c m : [SELECT Id, Name, Car_Model__c, Date__c FROM Car_Sells__c]) {
        //query for Car_Sells__c records
            options.add(new selectOption(m.Car_Model__c, m.Car_Model__c));
            //for all records found - add them to the picklist options
        }
        return options; //return the picklist options
    }

   List<Car_Sells__c> mktsys;
   public void setAccts(String s) {
      accts =s;
   }
   public List<Car_Sells__c> getMktsys() {
      return mktsys;
   }
   public PageReference doSearch() {
      // Search by Exactly word
     mktsys = (List<Car_Sells__c>)[SELECT Id, Name, Cost__c, Date__c FROM Car_Sells__c WHERE Car_Model__c =: hiddenAccts];
 
     //String qryString = 'SELECT Id, Name, Cost__c FROM Car_Sells__c WHERE Car_Model__c =: accts';
     //mktsys = Database.query(qryString);
     return null;
   }

}

 I took out the second query in your doSearch method. I don't think you need it. 

 

On another note, I don't think that the picklist that you have created here is 100% in line with what you are trying to create. From my understanding, you want to be able to pick a car model from a picklist, click a button and have all the records related to that particular car model display. This will accomplish that, but you may find that you have duplicate car models in your picklist. The reason being that you are polling the picklist values from the object records. For example, if you have two car types that are Audi, you will get Audi listed twice in your picklist. I am not entirely sure if this was your intention. 

catchforshivacatchforshiva

Thank you for try.

 

your code not getting my answer.

 

 

Here probelm  is when i am selecting the picklist value and click to submit the command button,

i want to display the piclist value related fileds .  

 

For example: In the picklist values AUDI, BENZ, BMW are there.

 

am select the AUDI picklist value and click to submit the command button. 

the result to diplay AUDI car sold customer details to display. Just like Customer Name, Cost, Date.

 

 

Thanks & Regards

Shiva