The maximum number of cases an agent can have pending is 12. Once the pending case falls below 12 the auto-assignment should take place.
trigger test on Case (after insert) {
List<Id> caseIds = new List<Id>{};
integer intcount=0;
for (Case theCase:trigger.new)
caseIds.add(theCase.Id);
List<Case> cases = new List<Case>{};
AggregateResult[] counts = [SELECT count(id)calls FROM Case WHERE OwnerId=:UserInfo.getUserId() GROUP BY OwnerId];
for(AggregateResult c : counts )
{
intcount =integer.valueof(c.get('calls'));
System.debug('intcount ==>'+intcount );
if(intcount <12) {
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule = true;
c.setOptions(dmo);
}
else{
c.AddError('Does not allow' );
}
//cases.add(c);
System.debug('cases===>'+cases.size());
}
Database.upsert(cases);
}
Cheers..
trigger test on Case (after insert) {
List<Id> caseIds = new List<Id>{};
integer intcount=0;
for (Case theCase:trigger.new)
caseIds.add(theCase.Id);
List<Case> cases = new List<Case>{};
AggregateResult[] counts = [SELECT count(id)calls FROM Case WHERE OwnerId=:UserInfo.getUserId() GROUP BY OwnerId];
for(AggregateResult c : counts )
{
intcount =integer.valueof(c.get('calls'));
System.debug('intcount ==>'+intcount );
if(intcount <12) {
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule = true;
c.setOptions(dmo);
}
else{
c.AddError('Does not allow' );
}
//cases.add(c);
System.debug('cases===>'+cases.size());
}
Database.upsert(cases);
}
Cheers..