I’m jumping back in time reviewing some old code that I have in my hard drive, and I see a code that I feel it’s going to be really useful. Recently I read on a post that there’s no way so far to show the approval history of a record in a record detail page in Salesforce (unless you are up to install a free package from Appexchange ), so even this is a bit old and the fact that is built using Visualforce and a extension but it makes the job done I decided to create an small post showing how it’s done.
So basically we need one Visualforce page and one Extension Controller in my sample I name the files like this:
- AccountApprovalCloneExtension.cls
- AccountApprovalClone.page
From the extension controller, the magic happens on how the query is build so I have the getApprovalHistoryInformation method which uses this query (For this sample I used Account as the main object):
SELECT CompletedDate, CreatedById, CreatedDate,Id,IsDeleted,LastActor.Name,LastModifiedById,LastModifiedDate,ProcessDefinitionId,Status,SubmittedBy.name,
SystemModstamp,TargetObjectId,(SELECT ID, ProcessNodeId, StepStatus,Comments,TargetObjectId,Actor.Name, CreatedById,IsDeleted,IsPending,OriginalActor.Name,ProcessInstanceId,RemindersSent,CreatedDate FROM StepsAndWorkitems order by CreatedDate DESC,Id DESC) FROM ProcessInstance where ProcessInstance.TargetObjectId =: accountRecord.Id order By CreatedDate DESC,Id DESC
The visualforce page uses one apex:pageBlock and a repeat component just to render the list of steps coming from the controller and regular inline script validation, so no really anything fancy here.
The final result looks like this:
You can grab the code from this GIST i created: https://gist.github.com/emoran/04696b57600e0f892ffa714c88b80a54 hope this is helpful, next step here would be to do the same but with a LWC of course.