Created
March 11, 2022 15:15
-
-
Save emoran/04696b57600e0f892ffa714c88b80a54 to your computer and use it in GitHub Desktop.
Approval History Clone for Salesforce Account. Allows to show the Approval History for an Object.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page standardController="Account" extensions="AccountApprovalCloneExtension" > | |
<apex:pageBlock title="Approval History Clone"> | |
<table class="list" border="0" cellspacing="0"> | |
<tbody> | |
<tr class="headerRow"> | |
<th class="actionColumn" scope="col">Action</th> | |
<th scope="col" class=" zen-deemphasize">Date</th> | |
<th scope="col" class=" zen-deemphasize">Status</th> | |
<!--<th scope="col" class=" zen-deemphasize">Assigned To</th>--> | |
<th scope="col" class=" zen-deemphasize">Comments</th> | |
<th scope="col" class=" zen-deemphasize">Overall Status</th> | |
</tr> | |
<apex:repeat value="{!approvalHistoryInformation}" var="processInstance"> | |
<tr class="tertiaryPalette extraRow dataRow even first"> | |
<td class="actionColumn"></td> | |
<td class="actionColumn"></td> | |
<td class="actionColumn"></td> | |
<td class="actionColumn"></td> | |
<td class="actionColumn"> | |
<div class="extraStatusDiv_P" style="background-color:{!IF(processInstance.Status=='Rejected','#FB8A8C',IF(processInstance.Status=='Pending','#FFD74B',IF(processInstance.Status=='Approved','#A1F78D','')))}; color: black;font-weight: bold;"> | |
<img src="{!IF(processInstance.Status=='Rejected','/img/icon/reject12.gif',IF(processInstance.Status=='Pending','/img/icon/pending12.gif',IF(processInstance.Status=='Approved','/img/icon/approve12.gif','')))}" alt="" class="extraStatus" title=""/> | |
<span class="extraStatus">{!processInstance.Status}</span> | |
</div> | |
</td> | |
<apex:repeat value="{!processInstance.StepsAndWorkitems}" var="step"> | |
<tr class="dataRow even first"> | |
<td class="dataCell"> | |
<div style="display:{!IF($Profile.Name != 'System Administrator','none','')}"> | |
<a href="/p/process/ProcessInstanceWorkitemWizardStageManager?id={!step.Id}" style="display: {!IF(step.IsPending == false,'none','')}" class="actionLink">Approve / Reject</a> | |
</div> | |
</td> | |
<td class="dataCell"> | |
<apex:outputText value="{0, date, MM/d/yyyy hh:mm a}"> | |
<apex:param value="{!step.CreatedDate + offset}" /> | |
</apex:outputText> | |
</td> | |
<td class="dataCell"> {!IF(step.StepStatus=='Started','Submitted',step.StepStatus)} by: <a href="/{!step.ActorId}" target="_blank">{!step.OriginalActor.Name}</a></td> | |
<td class="dataCell">{!step.Comments}</td> | |
<td class="dataCell"></td> | |
</tr> | |
</apex:repeat> | |
</tr> | |
</apex:repeat> | |
</tbody> | |
</table> | |
</apex:pageBlock> | |
</apex:page> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class AccountApprovalCloneExtension { | |
private final Account accountRecord; | |
public AccountApprovalCloneExtension(ApexPages.StandardController stdController) { | |
this.accountRecord = (Account) stdController.getRecord(); | |
} | |
public List<ProcessInstance> getApprovalHistoryInformation(){ | |
Map<Id,ProcessInstance> mapProcessInstance = new Map<Id,ProcessInstance>([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]); | |
return mapProcessInstance.values(); | |
} | |
/**a | |
* | |
*/ | |
public Double offset{ | |
get { | |
TimeZone tz = UserInfo.getTimeZone(); | |
return tz.getOffset(DateTime.now()) / (1000 * 3600 * 24.0); | |
} | |
} | |
} |
Can You Provide the Test Class for the Same
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Final result