+ Start a Discussion
Liam JeongLiam Jeong 

ProcessInstanceStep Trigger

Hey folks,

I would like to create a custom report type for Approval History(ProcessInstanceStep).

My first approach was creating a trigger or record-triggered flow on the ProcessInstanceStep object.
But for some reason, Salesforce doesn't allow me to create a trigger on the object.

Background information,
There are more than 2,000 submitted approvals daily based.
The client wants to maximize declarative tools' usability.(Not Programatical solution)

How should I resolve this issue?

Much obliged, in advance.
Liam
Best Answer chosen by Liam Jeong
Naveen KNNaveen KN
Thanks for the details, Liam.

I was in the assumption that it is for a single object. Then, it will be difficult to handle all the approval processes(multiple objects) from a single place.

I think we have to Go with Batch apex now!

--
Naveen 
 

All Answers

Naveen KNNaveen KN
Could you please add more details on why are we trying to write a trigger on the processinstancestep?
Liam JeongLiam Jeong
Hey Naveen,

Since the client wants to see the fields(Comment, Approver, Status etc.) on the ProcessInstanceStep on a report.
What would best practice for it?

Liam
Naveen KNNaveen KN
Hi Liam, 

As there is no option to create a report directly on ProcessInstanceStep (verified quickly in my dev org) we need to create a custom object to store the values and create a report. 

Considering this approval process is for the Opportunity object

Create a new field to track the status of the approvals, like submitted, approve, rejected in the opportunity object.. as you know, we can set this field status from the workflow field updates feature under each approval process initial submission action, approval actions, and rejection actions sections 

Create a new record triggered flow (as flow is the future, no Process builder please..) that triggers on the opportunity object update - new field value changed, in the flow we can get the opportunity id and pass it to the Apex class. In the Apex code, query the processinstance and process instance step, insert the record into the new object created, and create the reports based on the new object. 

I know you mentioned only declarative tools usage, unfortunately, the approval process-related objects are not yet available in the flow builder. :( Hoping to get it soon to avoid complex codes in the Apex. 

Hope this helps!

--
Naveen K N
Liam JeongLiam Jeong
Hey Naveen,
Thank you for your input.

Here's what I have done so far.
I've created a custom object to clone the ProcessInstanceStep object.
And also created Scheduled-Flow(to run it daily), Auto-launched flow(invoked by the scheduled flow), and Record-trigger flow(on the custom object to link it to the target object using lookup field).

I have run this resolution for 3 months so far. but I realized that some ProcessInstanceStep records are not being cloned.
I investigated and noticed that sometimes the flow hits the Governor Limit.
Since there's a limit of 2,000 executed elements at run time(Sometimes, there's more than 2,000 ProcessInstanceStep records daily)

My next thought was implementing a Batch Apex. but I wanted to try everything before I jump into the code world.

I hope you understand my situation.

Much obliged,
Liam
Naveen KNNaveen KN
ah got it. 

Just thought, why don't we update the custom object in real-time from the record-triggered flow? as it will not hit the governor limits(flow-related). at least we can reduce the sort of Apex code compared to batch class... However, we should write iteration logic on ProcessInstanceStep in both cases. 
Please keep us posted on the workarounds that you implement. Thanks. 

--
Naveen K N  

 
Liam JeongLiam Jeong
Hey Naveen,

There are several reasons.
1. The client wants to see the same fields on several sObjects(3-20 sObjects).
  -> Will need to implement every flow for each sObject.
2. Th org has enough background automation. In other words, it's pretty slow now.
  -> I refrain from adding more real-time automation.

Under my investigation, I haven't found any declarative solution.

What do you think?

Liam
Naveen KNNaveen KN
Thanks for the details, Liam.

I was in the assumption that it is for a single object. Then, it will be difficult to handle all the approval processes(multiple objects) from a single place.

I think we have to Go with Batch apex now!

--
Naveen 
 
This was selected as the best answer
finch loefinch loe
If You Are Looking For Best Online Pharmacy That Can Provide You Best Medications. Than, We Are Here To Provide You The Best Medications. Just Click On Links Below And Order Now.

OTC ADHD Pills (https://www.pharmacymedsonline.com/product-category/adhd/" target="_blank)
OTC Anti-Anxiety Pills (https://www.pharmacymedsonline.com/product-category/anti-anxiety/" target="_blank)
OTC Erectile-Dysfunction Pills (https://www.pharmacymedsonline.com/product-category/erectile-dysfunction/" target="_blank)
OTC Muscle-Relaxant Pills (https://www.pharmacymedsonline.com/product-category/muscle-relaxant/" target="_blank)
OTC Malaria Pills (https://www.pharmacymedsonline.com/product-category/malaria/" target="_blank)