function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KMK91KMK91 

Trigger on case Assignment rule

Create a trigger on case that if owner is external community user(profile = customer community user)then the check box "assign using Active assignment rules" should be active.

Thanks
KMK
Best Answer chosen by KMK91
Deepak Maheshwari 7Deepak Maheshwari 7
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);
    }
}

 

All Answers

Deepak Maheshwari 7Deepak Maheshwari 7
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);
    }
}

 
This was selected as the best answer
DeveloperDeveloper
HI deepak , i have same requriment , your code is working fine but, when ever reassign the assignment rule its not updated . could please help on that ................


Thanks in advance ...............