• Artur Artur 13
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
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.