+ Start a Discussion
SolutionSolution 

Assign cases to group of users in Round Robin manner

Hi,

 

I want case to assign to group of users in Round Robin manner. I have a workflow rule which is updating case's owner field to Case Queue. And I want to distribute cases among queue member.

 

I am writting After Update trigger to achieve this functionality. I am able to get the list of users which are member of Case Queue and list of cases which are assigned to Case Queue. But I am not getting how to assign cases to list of user in Round Robin manner.

 

Can someone please help me out? Thanks in advance..

ManojjenaManojjena

http://www.youtube.com/watch?v=oIL7ssD0ZHc go through link ,

 

 

or  Create a checkbox in user,write a trigger in case.

Query from user with your group users and while asigning make th echeckbox true.

Once all user will checked then update all checkbox false and repeat the same process.

 

 

 

ManojjenaManojjena

trigger CaseBeforeInsert on Case (Before Insert) {
Set<ID> caseIdSet=new Set<Id>();
Set<ID> groupMemberIdSet=new Set<ID>();
List<User> ToBeAssignedUserList=new List<User>();
List<User> userList=new List<User>();
for(Case cas:Trigger.new){
caseIdSet.add(cas.Id);
}

if(!caseIdSet.isEmpty()){
Group grp= [SELECT Id,Name,Type FROM Group WHERE Type = 'Queue' AND Name = 'YourQueueName'] ;
List<GroupMember> grpmembList =[Select UserOrGroupId From GroupMember where GroupId =:grp.Id];
for(GroupMember grpmemb : grpmembList){ groupMemberIdSet.add(grpmemb.UserOrGroupId);}
userList=[Select id,checkbox__c from User WHERE Id IN:groupMemberIdSet];
ToBeAssignedUserList=[Select id,checkbox__c from User WHERE Id IN:groupMemberIdSet AND checkbox__c =false];
if(!ToBeAssignedUserList.isEmpty()){

for(Case cas:Trigger.new){
cas.OwnerId=ToBeAssignedUserList[0].id;
}
ToBeAssignedUserList[0].checkbox__c=true;
try{
update ToBeAssignedUserList;
}catch(DmlException de){System.debug(de);}
}else{
List<User> ToBeUpdateUserList=new List<User>();
for(user usr:userList){
usr.checkbox__c=false;
ToBeUpdateUserList.add(usr);
}
try{
update ToBeUpdateUserList;
}catch(DmlException de){ System.debug(de);}
ToBeAssignedUserList= new List<User>();
ToBeAssignedUserList=[Select id,checkbox__c from User WHERE Id IN:groupMemberIdSet AND checkbox__c =false];
for(Case cas:Trigger.new){
cas.OwnerId=ToBeAssignedUserList[0].id;
}
ToBeAssignedUserList[0].checkbox__c=true;
try{
update ToBeAssignedUserList;
}catch(DmlException de){System.debug(de);}
}
}

 

Check this trigger it will work ,

 

Please let me know if u have any problem on same and if this post helps u please throw KUDOS by click on star at left.

Karthik AriharapakamKarthik Ariharapakam
Hey Manoj.. This is the best answer !! Thank you very much buddy !! Cheers :)
Kritika AnandKritika Anand
This code fails on bulk  insertion. If I insert bulk case records it assigns every case same value of owner. Please help me with this