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
Aki99Aki99 

Flooding picklist with string variable

Hi there,
I am trying to create a dependent picklist in a visual force page.
The first lists the price range of books and the second then lists the author list.
But when I try to add items to the second list by the code:
str = [SELECT name,price__c,author__c,publisher__c FROM Novel__c WHERE price__c<100 AND author__c =:this.options1]

it gives me the following error
: Invalid bind expression type of System.SelectOption for column of type String at line 26 column 117

here's my controller code
public class class12
{

    public string options ;
    public List<selectOption> options1 = new List<selectoption>();
    public string options2;
    public List<Novel__c> str = new List<Novel__c>();
   
    public class12(ApexPages.StandardController controller)
    {

    }

    public List<Novel__c> getStr() {

            if(options=='Below 100')
            { 
                options1.clear();
                for(Novel__c n:[SELECT author__c FROM Novel__c WHERE price__c<100 ORDER BY author__c])
                { 
                    this.options1.add(new SelectOption(String.valueof(n.author__c),string.valueof(n.author__c)));
                }
                getItems2();
               
                str.clear();
                str = [SELECT name,price__c,author__c,publisher__c FROM Novel__c WHERE price__c<100 AND author__c =:this.options1];
                return str;
            }
            else if(options == 'Above 100'){
                options1.clear();
                for(Novel__c n:[SELECT author__c FROM Novel__c WHERE price__c<100 ORDER BY author__c])
                { 
                    this.options1.add(new SelectOption(String.valueof(n.author__c),string.valueof(n.author__c)));
                }
                getItems2();
                str.clear();
                str = [SELECT name,price__c,author__c,publisher__c FROM Novel__c WHERE price__c>=100 AND author__c =:this.options1];
                return str;
            }
           else{ 
                //getItems2(null);
                str.clear();
                return str;
           }
          
    }


    public List<SelectOption> getitems2()
    {
        return this.options1;
    }
    public List<Novel__c> getnovelList()
    {
        return [SELECT name,price__c,author__c,publisher__c FROM Novel__c WHERE price__c>100];
    }
    public string getoptions()
    {
        return this.options;
    }
    public void setoptions(String opt)
    {
        this.options = opt;
    }
    public string getoptions2()
    {
        return this.options2;
    }
    public void setoptions2(String opt)
    {
        this.options2 = opt;
    }
    public List<SelectOption> getItems()
    {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new Selectoption('Below 100','Below 100'));
        options.add(new Selectoption('Above 100','Above 100'));      
        return options;
    }
    public pagereference preview()
    {
        return null;
    }
}
Is there any other way of adding a string variable in select list?
Thank you

Puja_mfsiPuja_mfsi

Hi,

In the below line 

str = [SELECT name,price__c,author__c,publisher__c FROM Novel__c WHERE price__c<100 AND author__c =:this.options1]

 

in where condition you compare the String fields "author__c" with the List of selectOption. How it is possible you can't do this.Pleasw explain what do you want at this place then I'll give you suggestion on same.

Aki99Aki99

oh yes i didnt notice that both are of different types.

Actually i want the select list to contain string values and from those string values I want to compare author__c  with