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
textualtextual 

test if case owner is user or queue

we have a process to store case data which works when the case owner is a user but fails when case owner is a queue. Is there a method for testing the object type of the owner id to ensure its a user? Another technique i saw is to query the user table for the owner id and see if any results returned.

 

there has to be an sobject method...right??

Best Answer chosen by Admin (Salesforce Developers) 
BharathimohanBharathimohan

Hi ,

 

This can be achieved very simply by using Owner.Type in your SOQL Query.

 

List<Case> ca = [SELECT Id,CaseNumber,OwnerId,Owner.Name,Owner.Type FROM Case];

 

for(Case c:ca)

{

       if(c.Owner.Type=='User')

       {

                  //do your operations here

       }

}

 

Possible values of Owner.Type are,

 

1. User

2. Queue

 

Please mark this post as solved, for the benefit of others.

 

Regards,

Bharathi

Salesforce For All

All Answers

NinoJoseNinoJose

I don't think there is an sobject method but you can check the first 3 characters of the ownerId to determine if the case owner is a user or queue.

 

005 - user

00G - queue.

 

There is a developer beta SOQL polymorhism - TYPEOF keyword for SOQL that might be useful for your scenario introduced for Winter 13 but its stil beta and personally I haven't tried it yet.

BharathimohanBharathimohan

Hi ,

 

This can be achieved very simply by using Owner.Type in your SOQL Query.

 

List<Case> ca = [SELECT Id,CaseNumber,OwnerId,Owner.Name,Owner.Type FROM Case];

 

for(Case c:ca)

{

       if(c.Owner.Type=='User')

       {

                  //do your operations here

       }

}

 

Possible values of Owner.Type are,

 

1. User

2. Queue

 

Please mark this post as solved, for the benefit of others.

 

Regards,

Bharathi

Salesforce For All

This was selected as the best answer
textualtextual

while this works, i dont really think of it as an elegant solution

it requires an extra call to the database in order to get the type

and it goes through some extraneious logic to work in bulk mode

 

it does solve my problem, just sayin...

 

if i could derive an sobject using the owner id, id prefer to test sobject.typeof

NinoJoseNinoJose

Thanks Bharathi. This is much better that the one I mentioned! cheers! :-)