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
GordymanLG2GordymanLG2 

SOQL Query to SELECT Cases owned by a Queue

Why won't this SOQL query work?

 

Case tmpCase = [select Id from Case where IsClosed = true and OwnerId like '00G' limit 1];

 

I am trying to get a particular type of Case in a test class.  The compiler complains whenever I put in the LIKE expression.

 

If this won't work, any suggestions on how to do it?

 

Thanks.

Best Answer chosen by Admin (Salesforce Developers) 
GordymanLG2GordymanLG2

I thought about but it was more complexity than I wanted in a test class.  If there was some easy way to query up all the queue ID without running into return record limits, then I might have considered it.  But I didn't want to embed IDs in classes if I can avoid it.  This Production org is always getting refreshed to sandboxes for dev work and it's already painful to modify if we actually want a working environment to test in.  And then you have to re-edit them manually to redeploy to production.  Just not worth it.

 

Thanks for the confirmation that LIKE can't be used with IDs.  How did you find that out?  I scoured all the documentation and nothing like that ever showed up.  You think for a company that wants to make the Force.com platform the global standard, they would understand that accurate and timely information that is of use to developers and integrators would save them a ton of trouble and buy them a lot of goodwill.  SFDC documentation is real pretty second class in a lot of areas.  IMHO, of course. :smileyvery-happy:

 

All Answers

Anand@SAASAnand@SAAS

You cannot use LIKE operator with ID fields. You will have to potentially build a list<ID> of all the queue ids that you are interested in and then use an IN clause.

GordymanLG2GordymanLG2

I thought about but it was more complexity than I wanted in a test class.  If there was some easy way to query up all the queue ID without running into return record limits, then I might have considered it.  But I didn't want to embed IDs in classes if I can avoid it.  This Production org is always getting refreshed to sandboxes for dev work and it's already painful to modify if we actually want a working environment to test in.  And then you have to re-edit them manually to redeploy to production.  Just not worth it.

 

Thanks for the confirmation that LIKE can't be used with IDs.  How did you find that out?  I scoured all the documentation and nothing like that ever showed up.  You think for a company that wants to make the Force.com platform the global standard, they would understand that accurate and timely information that is of use to developers and integrators would save them a ton of trouble and buy them a lot of goodwill.  SFDC documentation is real pretty second class in a lot of areas.  IMHO, of course. :smileyvery-happy:

 

This was selected as the best answer
Anand@SAASAnand@SAAS

You could store the Queue Id or Ids that you are looking for in a "Custom Setting". This helps externalize your ids from the Apex code and make it easier make changes specific to an environment.

Jan StaufenbergJan Staufenberg
Maybe there's someone else also interested in the possibility of filering by Owner-Type:
select Id from Case where IsClosed = true and Owner.Type = 'Queue'
I just figured out that it is that easy...