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
akallioWileyakallioWiley 

Getting Custom Chatter Action to work with Case Assignment Rules?

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;
Vinita_SFDCVinita_SFDC
Hello,

Is that a before trigger of after trigger? We can not invoke assignment rules in before triggers. Solution is to implement the assignment rule code in the "after" trigger instead of the "before" trigger.
akallioWileyakallioWiley
I will try to clarify:

The assignment rules work fine with the trigger...the trigger is an after trigger. 

The issue is that the Chatter feed item that should be inserted when the user clicks the submit button on the Chatter Action does not get inserted when this trigger is active.
Vinita_SFDCVinita_SFDC
Hello,

Could you share code? Also try checking debug logs for the submit button event.

Click path for debuig logs: Setup|Administration setup|monitoring|Debug logs
akallioWileyakallioWiley
all of the code is in the first post.
hcreel1.3964468584207637E12hcreel1.3964468584207637E12
How do you know which parts of the trigger should be replaced with data/records/etc from your Org? I am not sure what is standard and what is plug in play here. But I have no coding experience...