Skip to main content

 I need to automatically create a Chatter post on a Case whenever its pending approval request is reassigned to another user using the standard Reassign action. Since triggers and record-triggered flows aren't supported on ProcessInstanceWorkitem, and the Case itself doesn't change, I'm not sure how to capture this event. Has anyone solved this, whether with scheduled polling, a custom reassign component, or another approach? Any suggestions or sample code would be appreciated.  

 

#Trailhead  #Salesforce Developer  #Salesforce Admin  #Salesforce  #TrailblazerCommunity  #Sales Cloud  #Apex  #Salesforcecommunity  #Salesforce_developer

2 answers
  1. Sep 25, 8:00 AM

    You’re correct that there isn’t a direct trigger point here. ProcessInstanceWorkitem doesn’t support Apex triggers or record-triggered flows, and reassigning the approval doesn’t update the Case itself. 

     

    If you need to keep the standard Reassign action, I’d handle it with scheduled Apex:

    1.  Run a scheduled job every few minutes. 
    2.  Query new ProcessInstanceStep records where StepStatus = 'Reassigned'. 
    3.  Use ProcessInstance.TargetObjectId to identify the related Case. 
    4.  Query the pending ProcessInstanceWorkitem for that process instance to get the newly assigned ActorId. 
    5.  Insert a FeedItem with the Case ID as ParentId. 
    6.  Store the processed ProcessInstanceStep.Id in a small custom log object with a unique/external-ID field. 
    7.  Skip any step already in that log so rerunning the job can’t create duplicate Chatter posts. 

    I’d also test it by reassigning the same approval twice and then running the job twice. The expected result should be two Chatter posts total, with no additional posts from the second job run. 

     

    If real-time posting is absolutely required, the other option is to replace the standard Reassign experience with a custom Flow/LWC backed by Apex. That custom action would update ProcessInstanceWorkitem.ActorId and create the Case FeedItem in the same transaction. But the existing standard Reassign action can’t be intercepted directly.

0/9000