SOQL query where condition for non alpha characters

apexsoql

I have a field which contains values like [1234] – Sample, [1234F] – Face Sample and further more. I want to get the rows using SOQL query with this field in where condition, when using below query there are no rows returned

Select Name, Id, Sample__c from Custom_Object__c where Sample__c = '[1234] - Sample'

Even checked in Developer Console under Query tab, it did not returned any rows. But with below query I got results (which included few unwanted rows too because of Like condition)

Select Name, Id, Sample__c from Custom_Object__c where Sample__c LIKE '%1234%'

But I want only rows which were matching with entire value rather than LIKE. Please suggest me how to achieve it.

Note sometimes values can be "[1234] & [1234F] – Sample case"

Best Answer

That query should work. However, please be aware that there may be multiple contiguous spaces in your string; make sure you're paying attention. For example, here's an example using an Account:

Query Name = [1234] - sample

As you can see, I had no problem querying the record. So, there might be an extra space somewhere, such as [1234] - Sample or [1234] - Sample. These extra spaces may not always appear in some cases, so try querying the record and checking it carefully using the Data Loader or Query Editor.

Related Topic