+ Start a Discussion
Adriana VoyceAdriana Voyce 

Apex Class Approval Processes ActorID, OriginalActorid, and SystemModstamp to display names and Est - and adjust Controller columns

Hi All, 

Please keep your responses as simple as possible, I am learning :)

I created A Class, A controller, and a VF template to display the approval process details, however... The values returned are UserIDs and GMT time stamp - Additionally I can't seem to get a nice table in my visualforce template it doesn't seem to respect the percentages I give it or setting it to 100%. Image of wants below along with my code.

I assume I need to tell my class to give me the Actorname but thats not one of the values I can pull from = getApprovalSteps not sure how to accomplsih this or do I do this somwhere else? 

Class: 

public class OpportunityApprovalHistoryController {
    public String opptyId {get;set;}
    public List<ProcessInstanceHistory> getApprovalSteps() 
    {if (opptyId != null) {Opportunity quote = 
        
[Select Id, 

(Select TargetObjectId, SystemModstamp, StepStatus, RemindersSent, ProcessInstanceId, OriginalActorId, IsPending, 
IsDeleted, Id, CreatedDate, CreatedById, Comments, ActorId From ProcessSteps order by SystemModstamp desc) 

from Opportunity where Id = :opptyId];

 return quote.ProcessSteps;}
 
 return new List<ProcessInstanceHistory> ();}}

Controller:
<apex:component controller="OpportunityApprovalHistoryController" access="global">

<apex:attribute name="oppId" assignTo="{!opptyId}" type="String" description="Id of the opportunity"/>

<apex:dataTable value="{!approvalSteps}" var="step">

<style></style>

<apex:facet name="caption">Approval History</apex:facet>
<apex:facet name="header">Details</apex:facet>

<apex:column width="20%">
<apex:facet name="header">Date</apex:facet>
<apex:outputText value="{!step.SystemModstamp}"/>
</apex:column>

<apex:column width="20%">
<apex:facet name="header">Status</apex:facet>
<apex:outputText value="{!step.StepStatus}"/>
</apex:column>

<apex:column width="20%" >
<apex:facet name="header">Assigned To</apex:facet>
<apex:outputText value="{!step.OriginalActorid}"/>
</apex:column>

<apex:column width="20%">
<apex:facet name="header">Actual Approver</apex:facet>
<apex:outputText value="{!step.ActorID}"/>
</apex:column>

<apex:column width="20%">
<apex:facet name="header">Comments</apex:facet>
<apex:outputText value="{!step.Comments}"/>
</apex:column>

</apex:dataTable>
</apex:component>

VF Template

<messaging:emailTemplate subject="Opportunity {!relatedTo.Name} Submitted for {!relatedTo.Subscription_Discount_Percent__c}% Subscription Discount" recipientType="User" relatedToType="Opportunity">
<messaging:HtmlEmailBody >

<p>Hello {!recipient.Name},</p>

<p>Opportunity: {!relatedTo.Name} for {!relatedTo.Account.Name} has been submitted for approval: </p>

<html>
<head>
<meta content="text/css;charset=utf-8" http-equiv="Content-Type"/>
<meta name="Template" content="Response"/>
</head>
<body>
<p><b>Approval History</b>

<c:opportunityapprovalhistory oppId="{!relatedTo.Id}" />

</p>
</body>
</html>
</messaging:HtmlEmailBody>
</messaging:emailTemplate>

WHAT I WANT

User full name not ID; Date in this format 5/16/2017 Est, and columns that auto size to the text along with borders on the table. 

User-added image
Best Answer chosen by Adriana Voyce
Nithesh NNithesh N
Try Running this Query again in the Developer Console Query Editor.  And verify the results.
Select Id, 
              (Select TargetObjectId, SystemModstamp, StepStatus, OriginalActor.Name, IsPending, 
              IsDeleted, Id, CreatedDate, CreatedById, Comments, Actor.Name From ProcessSteps order by SystemModstamp desc) 
         
             from Opportunity

If  you are getting Results in the Query Editor, Replace the Soql Query in Class as follows
[Select Id, 
             
             (Select TargetObjectId, SystemModstamp, StepStatus, RemindersSent, ProcessInstanceId, OriginalActor.Name, IsPending, 
              IsDeleted, Id, CreatedDate, CreatedById, Comments, Actor.Name From ProcessSteps order by SystemModstamp desc) 
         
             from Opportunity where Id = :opptyId];

Then, Change the Datatable Visualforce Markup.
 
<apex:component controller="OpportunityApprovalHistoryController" access="global">

<apex:attribute name="oppId" assignTo="{!opptyId}" type="String" description="Id of the opportunity"/>

<apex:dataTable value="{!approvalSteps}" var="step" border="4" align="center" cellpadding="8">

<style></style>

<apex:facet name="caption">Approval History</apex:facet>
<apex:facet name="header">Details</apex:facet>

<apex:column width="20%">
<apex:facet name="header">Date</apex:facet>
<apex:outputtext value="{0, date, medium}">
        <apex:param value="{!step.SystemModstamp}"></apex:param>
 </apex:outputtext>
</apex:column>

<apex:column width="20%">
<apex:facet name="header">Status</apex:facet>
<apex:outputText value="{!step.StepStatus}"/>
</apex:column>

<apex:column width="20%" >
<apex:facet name="header">Assigned To</apex:facet>
<apex:outputText value="{!step.OriginalActor.Name}"/>
</apex:column>

<apex:column width="20%">
<apex:facet name="header">Actual Approver</apex:facet>
<apex:outputText value="{!step.Actor.Name}"/>
</apex:column>

<apex:column width="20%">
<apex:facet name="header">Comments</apex:facet>
<apex:outputText value="{!step.Comments}"/>
</apex:column>

</apex:dataTable>
</apex:component>

Hope it Works, Mark this Solution a best Solution to Mark this thread as Solved. 

Best, 
Nithesh.

 

All Answers

Nithesh NNithesh N
Hi Adriana, 
​To get a Good Table layout with borders, try PageBlockTable instead of DataTable. 
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_pageBlockTable.htm

To get User Name , Refer this Link 
https://developer.salesforce.com/forums/?id=906F0000000BHqJIAW

For date format, I would do somethink Like this
<apex:outputText value="{0,date,MM'/'dd'/'yyyy}">
    <apex:param value="{!contact.date}" /> 
</apex:outputText>

Let me know if it works.

Best, 
Nithesh
 
Adriana VoyceAdriana Voyce
Hi Nithesh, 

I have reviewed all of the links, but they did not work for me. When I try to use Pageblock I get errors same with the second link, pehaps I just don't know how to referwence it prperly in my class... Any ideas, or can you write the code of how to do this because I've been trying for days with no luck :( I will give the date a shot... Thanks! 
Nithesh NNithesh N
Let me Try that in my Dev Org. 
Nithesh NNithesh N
Try this Code for Pageblock table...
<apex:component controller="OpportunityApprovalHistoryController" access="global">

<apex:attribute name="oppId" assignTo="{!opptyId}" type="String" description="Id of the opportunity"/>
    
    <apex:pageBlock title="Approval History">
        
        <apex:pageBlockTable value="{!ApprovalSteps}" var="step"  columnsWidth="20%">
            
            <apex:column headervalue="Date">
                <apex:outputText value="{0,date,MM/dd/yyyy}">
                    <apex:param value="{!step.SystemModstamp}"/>
                </apex:outputText>
            </apex:column>
            
            <apex:column headerValue="Status" value="{!step.StepStatus}" />
            <apex:column headerValue="Assigned To" value="{!step.OriginalActorid}" />
            <apex:column headerValue="Actual Approver" value="{!step.Actorid}" />
            <apex:column headerValue="Comments" value="{!step.Comments}" />
            
            
        </apex:pageBlockTable>
        
    </apex:pageBlock>

</apex:component>

 
Nithesh NNithesh N
And for Actor Name, try this and let me know if it works
 
Select TargetObjectId, SystemModstamp, StepStatus, RemindersSent, ProcessInstanceId, OriginalActor.Name, IsPending, 
              IsDeleted, Id, CreatedDate, CreatedById, Comments, Actor.Name From ProcessSteps order by SystemModstamp desc

Use Actor.Name instead of ActorId
Adriana VoyceAdriana Voyce
Page block did not work... Trying the other one now


User-added image
Adriana VoyceAdriana Voyce
The actor name code did not work either :(
Nithesh NNithesh N
Then, lets Modify datatable 
<apex:component controller="OpportunityApprovalHistoryController" access="global">

<apex:attribute name="oppId" assignTo="{!opptyId}" type="String" description="Id of the opportunity"/>

<apex:dataTable value="{!approvalSteps}" var="step" border="4" align="center" cellpadding="8">

<style></style>

<apex:facet name="caption">Approval History</apex:facet>
<apex:facet name="header">Details</apex:facet>

<apex:column width="20%">
<apex:facet name="header">Date</apex:facet>
<apex:outputText value="{!step.SystemModstamp}"/>
</apex:column>

<apex:column width="20%">
<apex:facet name="header">Status</apex:facet>
<apex:outputText value="{!step.StepStatus}"/>
</apex:column>

<apex:column width="20%" >
<apex:facet name="header">Assigned To</apex:facet>
<apex:outputText value="{!step.OriginalActorid}"/>
</apex:column>

<apex:column width="20%">
<apex:facet name="header">Actual Approver</apex:facet>
<apex:outputText value="{!step.ActorID}"/>
</apex:column>

<apex:column width="20%">
<apex:facet name="header">Comments</apex:facet>
<apex:outputText value="{!step.Comments}"/>
</apex:column>

</apex:dataTable>
</apex:component>

 
Adriana VoyceAdriana Voyce
<3 the table looks really nice thank you!!! Now I just need to figure out how to get name instead of ID and the date... I tried this but it didn't work

<apex:column width="20%">
<apex:facet name="header">Date</apex:facet>
<apex:outputText value="{!step.SystemModstamp}"/>
<apex:outputText value="{0,date,MM/dd/yyyy}">
<apex:param value="{!step.SystemModstamp}"/>
</apex:outputText>
</apex:column>
 
Nithesh NNithesh N
Lets Try this one last time, 
<apex:column width="20%">
<apex:facet name="header">Date</apex:facet>
<apex:outputtext value="{0, date, medium}">
        <apex:param value="{!step.SystemModstamp}"></apex:param>
 </apex:outputtext>
</apex:column>

 
Adriana VoyceAdriana Voyce
YESSS!!! Date is fixed! last piece of the puzzle is the ID to name! ps: You are wesome!!!
Adriana VoyceAdriana Voyce
I got it!!!!   Nitesh - THANK YOU!!!! You were a great help! 

The class should be: 

public class OpportunityApprovalHistoryController {
    public String opptyId {get;set;}
    public List<ProcessInstanceHistory> getApprovalSteps() 
    {if (opptyId != null) {Opportunity quote = 
        
[Select Id, 

(Select TargetObjectId, SystemModstamp, StepStatus, RemindersSent, ProcessInstanceId, OriginalActorId, OriginalActor.name, IsPending, 
IsDeleted, Id, CreatedDate, CreatedById, Comments, Actor.Name, ActorId From ProcessSteps order by SystemModstamp desc) 

from Opportunity where Id = :opptyId];

 return quote.ProcessSteps;}
 
 return new List<ProcessInstanceHistory> ();}}


The controller Should be:

<apex:column width="20%" >
<apex:facet name="header">Assigned To</apex:facet>
<apex:outputText value="{!step.OriginalActor.name}"/>
</apex:column>

<apex:column width="20%">
<apex:facet name="header">Actual Approver</apex:facet>
<apex:outputText value="{!step.Actor.Name}"/>
</apex:column>
Nithesh NNithesh N
Try Running this Query again in the Developer Console Query Editor.  And verify the results.
Select Id, 
              (Select TargetObjectId, SystemModstamp, StepStatus, OriginalActor.Name, IsPending, 
              IsDeleted, Id, CreatedDate, CreatedById, Comments, Actor.Name From ProcessSteps order by SystemModstamp desc) 
         
             from Opportunity

If  you are getting Results in the Query Editor, Replace the Soql Query in Class as follows
[Select Id, 
             
             (Select TargetObjectId, SystemModstamp, StepStatus, RemindersSent, ProcessInstanceId, OriginalActor.Name, IsPending, 
              IsDeleted, Id, CreatedDate, CreatedById, Comments, Actor.Name From ProcessSteps order by SystemModstamp desc) 
         
             from Opportunity where Id = :opptyId];

Then, Change the Datatable Visualforce Markup.
 
<apex:component controller="OpportunityApprovalHistoryController" access="global">

<apex:attribute name="oppId" assignTo="{!opptyId}" type="String" description="Id of the opportunity"/>

<apex:dataTable value="{!approvalSteps}" var="step" border="4" align="center" cellpadding="8">

<style></style>

<apex:facet name="caption">Approval History</apex:facet>
<apex:facet name="header">Details</apex:facet>

<apex:column width="20%">
<apex:facet name="header">Date</apex:facet>
<apex:outputtext value="{0, date, medium}">
        <apex:param value="{!step.SystemModstamp}"></apex:param>
 </apex:outputtext>
</apex:column>

<apex:column width="20%">
<apex:facet name="header">Status</apex:facet>
<apex:outputText value="{!step.StepStatus}"/>
</apex:column>

<apex:column width="20%" >
<apex:facet name="header">Assigned To</apex:facet>
<apex:outputText value="{!step.OriginalActor.Name}"/>
</apex:column>

<apex:column width="20%">
<apex:facet name="header">Actual Approver</apex:facet>
<apex:outputText value="{!step.Actor.Name}"/>
</apex:column>

<apex:column width="20%">
<apex:facet name="header">Comments</apex:facet>
<apex:outputText value="{!step.Comments}"/>
</apex:column>

</apex:dataTable>
</apex:component>

Hope it Works, Mark this Solution a best Solution to Mark this thread as Solved. 

Best, 
Nithesh.

 
This was selected as the best answer
Nithesh NNithesh N
Lol..Same as my Solution. Please Mark this Solution a best Solution to Mark this thread as Solved.