• Deepak@UXLT
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

I thought I'd share since figuring this out was kind of crappy.  Since you can't (or I couldn't find how) concatenate a string in an SOQL query to combine wildcards like % and _ to make a query, you need to do so with the variable you want to pass in.

 

So if you want to do an SOQL query using LIKE, wild cards, and an Apex variable, this will work.

 

//create a string
String s = 'mystring';

//add wildcards around it to be more flexible in the search
s = '%' + s + '%';

//create an SOBject list with the results from our query
SObject[] obj = [select id from SObjectName where Name LIKE :s];

 

and this will return any row from the SObjectName where the "Name" field has "mystring" in it.