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
Karthik SankarKarthik Sankar 

Problem in querying the Queue Sobject with the same QueueName

I want to get the QueueId from the Queue Sobject and assign it to the Case OwnerId field in Apex.

The QueueId will be based on the SobjectType and the Queue Name.

I am using this query for the purpose.
QueueSobject que = [Select Id, SobjectType, QueueId, Queue.Name from QueueSobject where SobjectType = 'Case' AND Queue.Name = 'Water Application Support'];

But since the Queue Name is not unique (unlike RecordType where you can't have same RecordTypeName for an object), if there are two Queues with the same name and related to same SobjectType, the query will fail to return a single record and my assignment of OwnerId will throw an exception.

Salesforce allows you to create duplicate queue records with the same Name and related SobjectType. There will be no difference between these two records except for their Ids.

But I don't want to hard-code the Id value in the query.

Please suggest me in this to get the appropriate QueueId.

Thanks,
Karthik.
harryZharryZ

If there are two queues, how do you know which queue is the one you want, is there any additions such as createddate, lastmodifieddate?

 

Karthik SankarKarthik Sankar

Hi Harryz,

 

That was my question. I am not able to differentiate between two queues with the same name and related objects.

 

Say for example, we can get the RecordTypeId in a query using its SobjectType and Name, but the same doesn't apply to QueueId.

 

I don't want to drill down on any other field like id, createddate, etc since these are all system-generated and I don't want to use hard-coded values.

rcardosorcardoso

Try this.

 

[select id from QueueSobject where SobjectType = 'Case' AND Queue.DeveloperName = 'theDeveloperName']

 

Does salesforce alow to duplicate the DeveloperName?

Artur Artur 13Artur Artur 13
DeveloperName is unique.