

trigger CaseAssignment on Case (after insert,after update) {
//Variable decleration
List<Case> caseList = new List<Case>();
User integrationUserObj = new User();
//Fetching the assignment rules on case
AssignmentRule AR = new AssignmentRule();
AR = [select id from AssignmentRule where SobjectType = 'Case' and Active = true limit 1];
//Creating the DMLOptions for "Assign using active assignment rules" checkbox
Database.DMLOptions dmlOpts = new Database.DMLOptions();
dmlOpts.assignmentRuleHeader.assignmentRuleId= AR.id;
if(Trigger.isAfter && Trigger.isInsert){
//Fetching the Community User details
integrationUserObj = [SELECT Id, Name FROM User where Profileid= '00e28000001hb4Y' LIMIT 1];
for (Case caseObj : Trigger.new) {
if (caseObj.OwnerId == integrationUserObj.Id) {
Case newCase = new Case(Status = 'New') ;
//Setting the DMLOption on Case instance
newCase.setOptions(dmlOpts);
caseList.add(newCase);
}
}
Database.update(caseList, dmlOpts);
}
}