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
ronshayronshay 

Use of Like Operator in SOQL

Im using Sforce 4.0 and have a Select statement built:

strSQL = "Select " & _

"ID, Name, pbClientID__c," & _

"Industry, LastModifiedDate, Type, RecordTypeID," & _

"BillingStreet, BillingCity, BillingState, BillingPostalCode " & _

"From Account " & _

"Where Industry like '%Automotive%'

When I run this I get no records returned. 

When I run the following:

strSQL = "Select " & _

"ID, Name, pbClientID__c," & _

"Industry, LastModifiedDate, Type, RecordTypeID," & _

"BillingStreet, BillingCity, BillingState, BillingPostalCode " & _

"From Account " & _

"Where Industry = 'Automotive - Other' or " & _

" Industry = 'Automotive - Supplier'"

I get records returned.  Is there some trick to using the LIKE operator.

ScotScot

Hi Ronshay,

Bad news, sorry. The LIKE operator only works for string values ... and a picklist is not considered a string value. For picklists, you need to use the full values ... as you did in your second example.

Scot

ronshayronshay

Ouch!  How do you tell if a "stringed" value is part of a picklist?  Is it in the XML definition?

 

Thanks.  Not what I wanted to hear, but I'll find a work around. Documentation is not very clear on this.

ScotScot

From the HTML interface, you can view the fields (Setup/Studio/(object type)/Fields) and look for the "Data Type". According to the documentation, only those marked as "Text" work with like. I've proven that Currency, Picklist, Lookup, Date, Percent, and Record type don't work. I think that some of the other special ones (like URL) may work.

From the sforce explorer, you can browse the fields and look at the "type" value.

If you want to do it dynamically, then look at the type field of the fields property of the DescribeSObjectResult - a mouthful .. described in the API document on page 86-87.