0

I have a requirement where I have a search box on the vf page. Based on the search string I am returning accounts to the page. I have written a query which searches for account name based on the search string. But I want to compare the search string with all the fields in the object. Is there any possible way of achieving this...

Here is my Query...

String searchquery='Select Id,Name FROM Account WHERE Name LIKE \'%'+searchString+'%\'';

Thanks in Advance...

1 Answers1

0

To search across an object like that you want to use a SOSL query not SOQL.

String soslSearch = 'FIND \''+searchString+'\' IN ALL FIELDS RETURNING Account(Name)';

Also when doing queries in APEX using strings with user input make sure you consider escaping the inputs to maintain security.

acrosman
  • 12,814
  • 10
  • 39
  • 55