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
Matt Cooper 7Matt Cooper 7 

Can you run a trigger off of ProcessInstance?

Hi, 

I am trying to build a trigger that runs directly after a Salesforce approval process is submitted.  Basically, I am trying to copy the approval information into a separate custom object that will create records that have both the approval information (Approver Name, Approval Status, etc.) and my custom object record information.  This will allow me to run more relevant reports off of the approval instances (than available through [out of the box reports](https://docs.releasenotes.salesforce.com/en-us/summer14/release-notes/rn_forcecom_process_approval_history_reports.htm)).  I also need the ability to generate a document with the approval information on it (who approved and when) and I can't find a solution for that without creating records in another object with the approval information copied into it.

I have attempted to run the trigger off of my custom object, but it seems impossible for the trigger to be able to run every time I need it to.  For instance, if there are multiple approvers in a step, there doesn't seem to be a way to update a field on the custom object record until the step is over.  

My question is if there is a way to run triggers off of ProcessInstance records (and subsequently ProcessInstanceStep and ProcessInstanceNode records).  I can't seem to create a trigger using the ProcessInstance object.

Thanks,Matt

Bhaswanthnaga vivek vutukuriBhaswanthnaga vivek vutukuri
Hi Matt, we can't run a trigger on process instance. we have to run it on object.
Matt Cooper 7Matt Cooper 7
Hi Bhaswanthnaga,  thanks for the reply.  Is there a way to run it on each object, but have the trigger run each time any behavior is taken with regards to the approvals?  For example, can we have it run when each individual approver takes action during one step? 
Bhaswanthnaga vivek vutukuriBhaswanthnaga vivek vutukuri

Yeah we can write logic for every object that is using approval process

Matt Cooper 7Matt Cooper 7
So, I have attempted to do this, but I can't seem to figure out how to have the trigger run from changes to the ProcessInstance objects as opposed to my custom object.  One approver approving in a step doesn't act as an Update on the custom object record, so therefore I can't get the trigger to run unless it's at minimum, the beginning or end of a step (as I can do a field update on the custom object record).  Do you have any exmples of how the above could be achieved?

Here is a link to another question I have asked regarding this issue if you want to look at the trigger so far: https://developer.salesforce.com/forums/ForumsMain?id=906F0000000kAFNIA2
Bhaswanthnaga vivek vutukuriBhaswanthnaga vivek vutukuri

If we take a custom status field in the object and update that field whenever the record is approved.

In trigger check the value of the field and compate to the old value if(new value = approved and Old vlaue!=approved) then do your logic

Matt Cooper 7Matt Cooper 7
But, unless I'm missing something, there isn't a way to do a field update for one approver in a step that has multiple approvers. Therefore, the custom status field wouldn't update.
Anil Gudla 22Anil Gudla 22
Hi Matt, did you get a solution for this, I too trying to achieve something similar.
Matt Cooper 7Matt Cooper 7
Hi Anil, I did not figure out a solution for this. I ended up having to put this project on hold from a bandwidth perspective, but hopefully will look back into it at a future time.
Andréia Carvalho 25Andréia Carvalho 25
5 years later and I'm facing the same problem, did you manage to solve it?
FlynnFlynn
so~there is no solution to this problem yet?