You need to sign in to do that
Don't have an account?

approval process trigger
I have an approval process on a custom object that when submitted, the user submitting the record manually selects the approver in each step. Based on the requirements, the object is set to private. So, I need to write a trigger that will manually create read-only access to the approvers. I can create the read-only access sharing using apex code, but where I'm having trouble is with the ApprovalProcess classes.
I only want the trigger to fire when the record has been submitted for approval and the approval step is going to an approver.
It looks like I need to use the ProcessWorkItem and ProcessRequest classes. I can use the getNextApproverIds method to get the user Id of the approver to set the read-only access, but how do I identify if the record has been submitted for approval and is in a step to be approved?
Does anyone have a code sample? I've googled and found some examples of how to submit the record for approval using Apex, but I didn't find anything that shows how to identify the record was submitted for approval and getting the user Id of the next approver.
Thanks.
This link has code that queries and finds only items in a pending status. Per haps you could look at the SOQL in it and get what you need?
Here is an example I use to cancel all approvals currently pending for a particular record. Maybe it will help.
Hi starz
Thanks for your solution its working