• hcreel1.3964468584207637E12
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
I created a custom chatter action to create a Case from a custom object. Everythig works fine except for the fact that the Case Assignment rules didn't kick-in. 

My 2 options for assigning the case were to use workflow rules or write a trigger. I went with the trigger because I have 5 and counting assignment rules and I don't want to create a workflow rule for each. 

The trigger works fine too. The issue is that when the trigger is used the resulting ChatterFeedItem is not created....once the user hits 'Submit'  the case is created, but the Chatter post is not created. So, I'm looking for ideas on how to get that chatter post created. 

Here is the trigger's logic:

if(trigger.isInsert && trigger.isAfter) {
       //This will ensure that Case assignments are run even Cases are created through Chatter Actions or through some other service.
       //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;
      
       Set<Id> newCaseIds = new Set<Id>();
       List<Case> newCases = new List<Case>();
       
       for(Case newCaseId : trigger.new) {
           newCaseIds.add(newCaseId.Id) ;         
       }
       
        for(Case newCase : [select Id from Case where Id IN :newCaseIds]) {
           newCase.setOptions(dmlOpts);        
           newCases.add(newCase);
        }
       
        update newCases;