You need to sign in to do that
Don't have an account?
rahul reddy 21
Can any one help me how to query multi-select picklist values to filter the records on click of search button
Hi,
I have a picklist field on account object,using search button I am able to filter the records by selecting a picklist value.
but now i want to use the same picklist value as multi-select picklist.
can any one help me in resolving the issue.
Vf code:
<apex:page controller="ACCsearch">
<apex:form id="form">
<span>Name</span>
<apex:inputText value="{!searchstring}" label="Input"/>
<apex:selectList value="{!Typeoptions}" label="Type" size="2" multiselect="true" >
<span>Type</span>
<apex:selectOptions value="{!selectedType}"></apex:selectOptions>
</apex:selectList>
<apex:commandButton value="Searchrecords" action="{!search1}"/>
<apex:pageBlock title="Inst Records" id="Block1">
<apex:pageBlockSection id="section" collapsible="true" title="TABS">
<apex:pageBlockTable value="{!Instlist}" var="inst" >
<apex:column value="{!inst.Name}"/>
<apex:column value="{!inst.Type}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
apex code:
public class ACCsearch
{
public list<Account> Instlist{get;set;}
public string searchstring{get;set;}
public string Typeoptions{get;set;}
public ACCsearch()
{
string strqry ='select Name,Type from Account';
Instlist=Database.query(strqry);
}
public list<Selectoption> GetselectedType()
{
List<SelectOption> options = new List<SelectOption>();
Schema.DescribeFieldResult fieldResult =Account.Type.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
options.add(new SelectOption('None','--None--'));
for( Schema.PicklistEntry f : ple)
{
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return options;
}
public void search1()
{
string strqry ='select id,Name, Active__c,Type from Account where id !=null ';
if(Typeoptions!='None')
{
strqry =strqry +'and Type LIKE \'%'+Typeoptions+'%\'';
}
if(searchstring!='')
{
strqry =strqry +'and Name LIKE \'%'+searchstring+'%\'';
}
Instlist=Database.query(strqry);
}
}
I have a picklist field on account object,using search button I am able to filter the records by selecting a picklist value.
but now i want to use the same picklist value as multi-select picklist.
can any one help me in resolving the issue.
Vf code:
<apex:page controller="ACCsearch">
<apex:form id="form">
<span>Name</span>
<apex:inputText value="{!searchstring}" label="Input"/>
<apex:selectList value="{!Typeoptions}" label="Type" size="2" multiselect="true" >
<span>Type</span>
<apex:selectOptions value="{!selectedType}"></apex:selectOptions>
</apex:selectList>
<apex:commandButton value="Searchrecords" action="{!search1}"/>
<apex:pageBlock title="Inst Records" id="Block1">
<apex:pageBlockSection id="section" collapsible="true" title="TABS">
<apex:pageBlockTable value="{!Instlist}" var="inst" >
<apex:column value="{!inst.Name}"/>
<apex:column value="{!inst.Type}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
apex code:
public class ACCsearch
{
public list<Account> Instlist{get;set;}
public string searchstring{get;set;}
public string Typeoptions{get;set;}
public ACCsearch()
{
string strqry ='select Name,Type from Account';
Instlist=Database.query(strqry);
}
public list<Selectoption> GetselectedType()
{
List<SelectOption> options = new List<SelectOption>();
Schema.DescribeFieldResult fieldResult =Account.Type.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
options.add(new SelectOption('None','--None--'));
for( Schema.PicklistEntry f : ple)
{
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return options;
}
public void search1()
{
string strqry ='select id,Name, Active__c,Type from Account where id !=null ';
if(Typeoptions!='None')
{
strqry =strqry +'and Type LIKE \'%'+Typeoptions+'%\'';
}
if(searchstring!='')
{
strqry =strqry +'and Name LIKE \'%'+searchstring+'%\'';
}
Instlist=Database.query(strqry);
}
}
http://www.infallibletechie.com/2012/11/includes-keyword-in-soql.html
Regards,
Bharathimohan Ramamurthy
Salesforce For All (http://salesforceforall.blogspot.com/)
I tried that senario earlier,in the debug log I found error message stating cannot use INCLUDE for field which is of the datatype-picklist.That senario works for multipicklist datatype.I am in need of query for picklist datatype which can be use to select multiple values from the dropdown.
Regards,
rahul