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
mlundwallmlundwall 

Complex SOQL Select

Hi,

 

I have the OwnerId of a Case and need to figure out if it is a Id of a user or Queue. I could do this with two select queries but would like to do it in just one.

 

How do I write that?

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

You can actually use Owner.Type as a value as well. It will return a string of the appropriate type (i.e. "User" or "Group"). It's used like this:

 

List<Case> cases = [Select Id,OwnerId,Owner.Type From Case Where Id In :caseids];

From a trigger, for example, caseids might be Trigger.newMap.keySet().

All Answers

srikeerthisrikeerthi

Hi

 

You can try in this way like

 

Queuesobject[] q=[select queueid from queuesobject];

Case[] Cs=[select id,ownerid from Case  where ownerid=:UserInfo.getUserid() or ownerid = : q[0].queueid];

 

From this using single query you can retrieve the ownerid if it is user or of queue.

mlundwallmlundwall

Perfect thank you I will have a look at it.

srikeerthisrikeerthi

Hi

 

Please mark it as a solution if it resolves your problem,so that it will be helpful for others.

 

Thankyou

sfdcfoxsfdcfox

You can actually use Owner.Type as a value as well. It will return a string of the appropriate type (i.e. "User" or "Group"). It's used like this:

 

List<Case> cases = [Select Id,OwnerId,Owner.Type From Case Where Id In :caseids];

From a trigger, for example, caseids might be Trigger.newMap.keySet().

This was selected as the best answer
mlundwallmlundwall

Thanks worked perfectly, it wasn't that complex after all...