You need to sign in to do that
Don't have an account?
Passing a variable into a LIKE statement in a SOQL query
Can anyone tell me how I can pass a variable into a LIKE statement in a SOQL query?
If I hardcode the search sting I get records returned:
results = (List<Solution>)[SELECT Id, SolutionNumber, SolutionName, TimesUsed FROM Solution WHERE (SolutionName LIKE '%keywordhere%')];
What I need to do is pass a variable in for the keyword. I tried the following code but I get an error - Error: SolutionSearch Compile Error: unexpected token: '+'
results = (List<Solution>)[SELECT Id, SolutionNumber, SolutionName, TimesUsed FROM Solution WHERE (SolutionName LIKE '%' + searchText + '%')];
I have this code that works but I don't like how it imprecise the returned record are that are returned:
results = (List<Solution>)[FIND :searchText IN ALL FIELDS RETURNING Solution(Id, SolutionNumber, SolutionName, TimesUsed)] [0];
Thank you.
Okay, sorry about before. I set this up on my side to make sure this approach works.
All Answers
Try this.
Or with the parentheses:
Thanks for the reply!
When I used this:
results = (List<Solution>)[SELECT Id, SolutionNumber, SolutionName, TimedUsed FROM Solution WHERE SolutionName Like '%'+:searchText+'%'];
I got this:
Error: SolutionSearch Compile Error: unexpected token: '+'
When I used This:
results = (List<Solution>)[SELECT Id, SolutionNumber, SolutionName, TimesUsed FROM Solution WHERE SolutionName LIKE ('%' + searchText + '%')];
I got this:
Error: SolutionSearch Compile Error: unexpected token: '('
Any other thoughts?
Thank you.
Here is something I am currently using. You can probably just modify it to suit your needs.
hope it helps.
Okay, sorry about before. I set this up on my side to make sure this approach works.
What about the order of the string...
If I type "HP Laptop"...it working good but If I type "Laptop HP" its not working....
need some help...