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
radanradan 

How to access ProcessInstanceHistory for a record?

How does one access in Apex, the approval comments, history associated with a record that has gone through an approval process?

 

The Web Services API describes a ProcessInstanceHistory object - but also says it cannot be queried.

The documentation says:

 

 

Usage
To retrieve this object, issue a describe call on an object, which will return a query result for each ProcessInstance since the

object was created. You cannot use query().

To retrieve this object, issue a describe call on an object, which will return a query result for each ProcessInstance since theobject was created. You cannot use query().

 

To retrieve this object, issue a describe call on an object, which will return a query result for each ProcessInstance since theobject was created. You cannot use query().

 

Apex SObjectDescribe methods do not seem to provide a way to access the process history. 

 

Any clarification/help with getting access to the Approval Process history for a record would be much appreciated.

 

stwdevstwdev

Here's an example of the query you'd need to execute...

 

This example assumes you've got a custom object, Mileage, that has an approval process hooked up to it:

 

Select m.Name, m.Id, (Select Id, StepStatus, Comments, CreatedDate From ProcessSteps) From Mileage__c m

 

The approval comments are obtained from the sub-query on ProcessSteps.

radanradan

That works. Thanks for the pointer.