Pages

Monday, January 6, 2014

Salesforce: Approval Process status (2)

Last year, I blog about how to get Approval Process status using SOQL query to ProcessInstance object, see this blog.

Query to ProcessInstance (04g) will give you Status of approval, together with the date/time of when approval submitted and user submit it, see CreatedDate and CreatedById field.
Note: LastModifiedDate and LastModifiedById will NOT change when a user approve / reject an approval request)

If you need more information, such as:
  • Approver username
  • Original approver username
  • Date/time for each transaction
  • Step Status
  • Comments
You can query from ProcessInstanceStep (04h) object, example:
SELECT p.Id, p.ActorId, p.OriginalActorId, p.StepStatus, p.Comments, p.CreatedById, p.CreatedDate, p.ProcessInstance.Status from ProcessInstanceStep p WHERE p.ProcessInstanceId = '04g500000029HCmAAM'



ActorId is the user who is currently assigned the approval step, while OriginalActorId is the user who was originally assigned to this approval step. Query to this object will give full information on the approval steps for each approval.

Another object related to approval, it is ProcessInstanceWorkitem (04i), this object will stored all approval pending request. Meaning approval that has been approved, rejected and recalled will no longer available here. Sample query:
Select p.Id, p.ProcessInstanceId, p.ProcessInstance.Status, p.ProcessInstance.TargetObjectId, p.ActorId, p.OriginalActorId, p.CreatedById, p.CreatedDate from ProcessInstanceWorkitem p


For query to ProcessInstanceWorkitem, actually you can run Salesforce report All Pending Approval Requests. This is standard Salesforce report available from 'Administrative Reports' folder. 

And screenshot below for the result and compare with query result above.


No comments:

Post a Comment