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
paul-lmipaul-lmi 

how to determine if a case is queue owned

I'm working on a replacement for a home page dashboard that does not require a refresh every time one of our managers wants a picture of open cases in our org.  One of the issues I always hit, with Apex, and also with validation, workflow rules, etc, is properly detecting if a case is queue owned.  Is there a way to globally determine if a case is queue owned without having to rely on a formula that you need to update for every time a queue is added to the org?

Best Answer chosen by Admin (Salesforce Developers) 
David81David81

Not "Owner Type", "Owner.Type".

 

e.g. -

 

 

Case c = [SELECT Id,OwnerId,Owner.Type FROM Case WHERE Owner.Name='SOME QUEUE NAME' LIMIT 1];

system.debug(c.Owner.Type);

 

 

 

The debug would show "Queue".

All Answers

David81David81

You can pull Owner.Type when querying the Cases table. Then you just need to check to see if it is "Queue" or "User".

paul-lmipaul-lmi

what field is "Owner Type"?  i don't see this in the schema editor.

David81David81

Not "Owner Type", "Owner.Type".

 

e.g. -

 

 

Case c = [SELECT Id,OwnerId,Owner.Type FROM Case WHERE Owner.Name='SOME QUEUE NAME' LIMIT 1];

system.debug(c.Owner.Type);

 

 

 

The debug would show "Queue".

This was selected as the best answer
paul-lmipaul-lmi

two funny things came out of this little project

 

1. your solution worked like a charm.

2. salesforce dev support contacted my boss (org contact) about the queries I was using, because SF's SOQL couldn't optimize them, which meant we were being resource greedy (my words).  your code fixed that.  so they can optimize on (column = 'string', but not "column = NULL".  

 

thanks much