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
Joey HoJoey Ho 

LIKE comparison operator not working as expected

Hi all,

 

I have a weird problem where I am querying from my Sandbox evnironment the following using the LIKE operation using the following snippet of code:

 

string s = '%__c'; 
list<CaseHistory> hist = new list<CaseHistory>();
hist = [Select Field From CaseHistory Where Field like :s Order by Field Limit 10];

 I get a erro as follows:

 

Compile error at line 3 column 5
invalid operator on id field

 

I have no idean where I am going wrong but I seem to be following the query syntax correctly?

Is there a bug in Sandbox query with the LIKE operator?

 

Thanks for your help!

Best Answer chosen by Admin (Salesforce Developers) 
Grazitti InteractiveGrazitti Interactive

Hi,

 

 The LIKE operator is supported for string fields only. Field on CaseHistory is a Picklist and returns Id of ownerAssignment, ownerAccepted or ownerEscalated i.e OwnerId.

 

 

Go through following Idea.

 

https://success.salesforce.com/ideaView?id=08730000000HYwY

 

/**If this post helps you then please mark it as a solution and don't forget to give me kudo's.***/

 

Thanks

www.grazitti.com

All Answers

Grazitti InteractiveGrazitti Interactive

Hi,

 

 The LIKE operator is supported for string fields only. Field on CaseHistory is a Picklist and returns Id of ownerAssignment, ownerAccepted or ownerEscalated i.e OwnerId.

 

 

Go through following Idea.

 

https://success.salesforce.com/ideaView?id=08730000000HYwY

 

/**If this post helps you then please mark it as a solution and don't forget to give me kudo's.***/

 

Thanks

www.grazitti.com

This was selected as the best answer
jungleeejungleee
Just thought I would share: you could actually use the LIKE operator on a pickList field. You can try running the below query in developer console:
select StageName from opportunity where StageName LIKE '%Customer%'
Joey HoJoey Ho
Thanks but its a no-go.

Tried querying the CaseHistory object for changes in the Case on custom
fields that end with '__c'.

Here is the code:

string s = '%__c%';
list l = new list();
l = [Select Field From CaseHistory Where Field like :s];

Thanks.