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
SrishSrish 

Custom Search page with multi select picklist

My objective is to create a custom search page where I can search on the fields input through a multi-select picklist. This picklist consists the list of the fields in which the search is to be done.

 

To acieve the above motive the code provided needs to be modified such that the search is done on the values returned by the method name getSelectedValues(). Also the values assigned to the variable originalvalues should be the required fields(Name, Industry, Rating, Account_Region__c, Account_Priority__c, Account_Summary__c) of the object Account.

 

Please find the code attached and suggest the necessary modifications.

 

//vf code
<apex:page Controller="AccountSearch"> <apex:form > <apex:pageBlock mode="edit" id="block"> <apex:pageBlockSection ></apex:pageBlockSection> &nbsp;&nbsp;&nbsp;<label for="checkbox"> Limit to Account I own: </label> <input id="checkbox" type="checkbox"/> <apex:pageBlockSection > <apex:pageBlockSectionItem > <apex:outputLabel for="searchText">Search Text</apex:outputLabel> <apex:panelGroup > <apex:inputText id="searchText" value="{!searchText}"/> </apex:panelGroup> </apex:pageBlockSectionItem> </apex:pageBlockSection> <apex:actionStatus id="status" startText="requesting..."/> <apex:pageBlockSection > <apex:panelGroup > <apex:panelGrid columns="3" id="abcd"> <apex:selectList id="sel1" value="{!leftselected}" multiselect="true" style="width:150px" size="7"> <apex:selectOptions value="{!unselectedvalues}" /> </apex:selectList> <apex:panelGroup > <br/> <apex:CommandButton value=" > " action="{!selectclick}"/> <br/> <apex:CommandButton value=" < " action="{!unselectclick}"/> </apex:panelGroup> <apex:selectList id="sel2" value="{!rightselected}" multiselect="true" style="width:150px" size="7"> <apex:selectOptions value="{!SelectedValues}" /> </apex:selectList> </apex:panelGrid> </apex:panelGroup> </apex:pageBlockSection> <apex:pageBlockSection > <apex:commandButton value="Submit" action="{!search}" rerender="block"/> </apex:pageBlockSection> <apex:pageBlockSection title="Results" id="results" columns="1"> <apex:pageBlockTable value="{!results}" var="a"> <apex:column value="{!a.Name}"/> <apex:column value="{!a.Industry}"/> <apex:column value="{!a.Rating}"/> <apex:column value="{!a.Account_Region__c}"/> <apex:column value="{!a.Account_Priority__c}"/> <apex:column value="{!a.Account_Summary__c}"/> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page> ---------------------------------------------------------------- //controller class
public class AccountSearch { String searchText; List<Account> results; //assign the values i.e. fields to originalvalues Set<String> originalvalues = new Set<String> {'Name', 'Industry', 'Rating', 'Account Region', 'Account Priority', 'Account Summary'}; Public List<string> leftselected{get;set;} Public List<string> rightselected{get;set;} Set<string> leftvalues = new Set<string>(); Set<string> rightvalues = new Set<string>(); public String getSearchText() { return searchText; } public void setSearchText(String s) { searchText = s; } public List<Account> getResults() { return results; } public PageReference search() { results = (List<Account>)[FIND :searchText RETURNING Account(Name, Industry, Rating, Account_Region__c, Account_Priority__c, Account_Summary__c)][0]; return null; } public AccountSearch() { leftselected = new List<String>(); rightselected = new List<String>(); leftvalues.addAll(originalValues); } public PageReference selectclick() { rightselected.clear(); for(String s : leftselected) { leftvalues.remove(s); rightvalues.add(s); } return null; } public PageReference unselectclick() { leftselected.clear(); for(String s : rightselected) { rightvalues.remove(s); leftvalues.add(s); } return null; } //unselected values remain in the left box public List<SelectOption> getunSelectedValues() { List<SelectOption> options = new List<SelectOption>(); List<string> tempList = new List<String>(); tempList.addAll(leftvalues); tempList.sort(); for(string s : tempList) options.add(new SelectOption(s,s)); return options; } //selected values that get displayed in the right box are returned public List<SelectOption> getSelectedValues() { List<SelectOption> options1 = new List<SelectOption>(); List<string> tempList = new List<String>(); tempList.addAll(rightvalues); tempList.sort(); for(String s : tempList) options1.add(new SelectOption(s,s)); return options1; } }