You need to sign in to do that
Don't have an account?
Is it possible to use SOQL LIKE with IDs?
Hi all,
I'm just wondering if it is possible to use SOQL LIKE with IDs? I tried the following but without any luck.
List<Case> cases = [SELECT Id FROM Case WHERE Id LIKE '005%'];
What I'm trying to achieve is to fetch all cases owned by a user (and therefore not a queue). I know I could just fetch all active users and use IN but that would esentially create another query towards the database because I'd first have to fetch the users and then fetch the cases.
My current solution is this:
List<Case> cases = [SELECT Id, OwnerId, Urgent__c FROM Case WHERE (Owner.Profile.Name LIKE '%YFF%' OR Owner.Profile.Name LIKE '%YK%' OR Owner.Profile.Name LIKE '%YO%' OR Owner.Profile.Name LIKE '%YB%') AND OwnerId != '005200000013dtq' AND LastModifiedDate > :lastUpdated AND Reserve_Until__c = null];
I'm not too keen on this approach because I'd have to update this SOQL whenever a new profile should be added to the list which brings me back to my initial approach.
All suggestions are welcome.
Cheers.
/Søren Nødskov Hansen
According to the docs:
--- 8< ---
The LIKE operator is supported for string fields only.
--- 8< ---
which is a shame, as it would be useful.
All Answers
According to the docs:
--- 8< ---
The LIKE operator is supported for string fields only.
--- 8< ---
which is a shame, as it would be useful.
Hi Bob,
Thanks for the quick reply. I must have missed that in the documentation. Sorry about that.
And, yes, it would be very useful.
/Søren Nødskov Hansen
Alternatively you can fetch the owner first using the name, and then use the owner.id in the soql query. This approach will also prevent updating the id when you deploy your code from dev to test to live.
- A J
select id from case where owner.type = 'user'
Even better. Thanks, Simon.
/Søren Nødskov Hansen