+ Start a Discussion
dev_sfdc1dev_sfdc1 

Need help to assign Queue Case Owner in Trigger

Hi,
I tried to insert queue CaseOwner whenever Case is created.But it was failing to update. Even I tried to hardcode but its not working to me.
Please help me to assign.
trigger testChangeOwnerTrigger on Case (before insert) 
{
 //List<QueueSobject> queueuser = [SELECT Id,queue.Name, QueueId FROM QueueSobject WHERE SobjectType = 'Case' and queue.Name = 'Unassigned' limit 1];
     for(Case newCase : Trigger.New) 
     { 
         newCase.OwnerId ='00G90000001hkVN'; 
     }
     
}
Swati GSwati G
Assign QueueId in ownerId instead of QueueSobject Id.
dev_sfdc1dev_sfdc1
I tried that also but not inserting to me. Value passing to debug logs but in Case insertion not working to me.
 
Manish ChandraManish Chandra
Hi,

you will have to insert group id instead of queue id, just query the group id by queue name

Group g=[Select Id from Group where name=:qname];

 for(Case newCase : Trigger.New) 
     { 
         newCase.OwnerId = g.id;
     }