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
Arash TeimoupoorArash Teimoupoor 

search bar to show the results if they contains a word in apex

Hi everyone,

I have created a search bar(ProjectSearch) in VF page to show the records in the page based on the result for a specific field(Project_ID__C), but right now it showes the results if I put the exact value of that field(Project_ID__C), while I need it to show the results if I just enter a part of the value of that field(Project_ID__C). please advise:


 stdSetCont =  new ApexPages.StandardSetController(Database.getQueryLocator([Select id,,Project_ID__c from Charts__c where Project_ID__c =: ProjectSearch and HRS_Site_ID__c =: ApexPages.CurrentPage().getParameters().get('hrsId') Limit 10000]));
        
Best Answer chosen by Arash Teimoupoor
Hargobind_SinghHargobind_Singh
Try this:

ProjectSearch = '%' + ProjectSearch + '%';

 stdSetCont =  new ApexPages.StandardSetController(Database.getQueryLocator([Select id,,Project_ID__c from Charts__c where Project_ID__c like :ProjectSearch and HRS_Site_ID__c =: ApexPages.CurrentPage().getParameters().get('hrsId') Limit 10000]));

==========
ps: If your question/problem is resolved, please mark your post as 'Solved' so that community can benefit from solutions. 

All Answers

Hargobind_SinghHargobind_Singh
Try this:

ProjectSearch = '%' + ProjectSearch + '%';

 stdSetCont =  new ApexPages.StandardSetController(Database.getQueryLocator([Select id,,Project_ID__c from Charts__c where Project_ID__c like :ProjectSearch and HRS_Site_ID__c =: ApexPages.CurrentPage().getParameters().get('hrsId') Limit 10000]));

==========
ps: If your question/problem is resolved, please mark your post as 'Solved' so that community can benefit from solutions. 
This was selected as the best answer
Arash TeimoupoorArash Teimoupoor
Thanks, it worked