Hello friends, In this post you are going to learn, how to determine whether a record owner is a user or a queue using apex code. In this section i will post code sample, that you can use as per your requirements. so let's get started,

Check  record owner is a user or queue in apex

For this post, I am using case object.

In Apex

 //Replace with your org case id 
List<Case> caseList = [SELECT OwnerId FROM Case WHERE Id='5005j00000Ea1e3'];
System.debug('OwnerId^^ '+caseList[0].OwnerId);
if(String.valueof(caseList[0].OwnerId).startsWith('005')) {
System.debug('Owner is User');
}
if(String.valueOf(caseList[0].OwnerId).startsWith('00G')){
System.debug('Owner is Queue');
}

Output:


 

In Apex Trigger

 trigger CaseTrigger on Case (after insert,after update) {
for (Case objCase : Trigger.new) {
If (objCase.OwnerID.getsobjecttype() == User.sobjecttype) {
System.debug('Owner is User');
}
else{
System.debug('Owner is Queue');
}
}
}

Output:


 

In Formula

 BEGINS([Case].OwnerId, "005") //Return true if owner is User otherwise false
BEGINS([Case].OwnerId, "00G") //Return true if owner is Queue otherwise false
Hope you like this post, for any feedback or suggestions please feel free to comment. I would appreciate your feedback and suggestions.
Thank you.