0

I have a Visualforce Email Template that displays the approval history for an order. It uses a Visualforce component and apex class.

This is the code in the email template

<p><b>Approval History</b>
<c:OrderApprovalHistoryController orderId="{!relatedTo.Id}"/>
</p>

This is the code in the Component

<apex:component controller="OrderApprovalHistoryController" access="global">
<apex:attribute name="orderId" assignTo="{!orderId}" type="String" description="Id of the Order"/>  
    <apex:dataTable value="{!approvalSteps}" var="step" width="90%">
        <apex:column value="{!step.SystemModstamp}" headerValue="Date"/>
        <apex:column value="{!step.StepStatus}" headerValue="Status"/>
        <apex:column value="{!step.OriginalActorId}" headerValue="Assigned To"/>
        <apex:column value="{!step.ActorID}" headerValue="Actual Approver"/>
        <apex:column value="{!step.Comments}" headerValue="Comments"/>
    </apex:dataTable>
</apex:component>

This is the code in the Class

public class OrderApprovalHistoryController {
public String orderId {get;set;}
    public List<ProcessInstanceHistory> getApprovalSteps() {
      if (orderId != null) {
        Order order= [Select Id, (Select TargetObjectId, SystemModstamp, StepStatus, RemindersSent, ProcessInstanceId, OriginalActorId, IsPending, IsDeleted, Id, CreatedDate, CreatedById, Comments From ProcessSteps order by SystemModstamp desc) from Order where Id = :orderId];
        return order.ProcessSteps;
      }
      return new List<ProcessInstanceHistory> ();
    }

}

This is working fine now, but I need to display the step name (which I believe is process node name) in the email and pdf that is generated.

I changed the SOQL in the Class to include the ProcessNodeId and ProcessNode.Name and ran it in workbench. The desired results where generated. Here is the SOQL statement with the two fields.

Order order= [Select Id, (Select TargetObjectId, SystemModstamp, StepStatus, RemindersSent, ProcessInstanceId, OriginalActorId, IsPending, IsDeleted, Id, CreatedDate, CreatedById, Comments, ActorId, ProcessNodeId, ProcessNode.Name From ProcessSteps order by SystemModstamp desc) from Order where Id = :orderId];

My problem is that when I try to add the field to the component, I get an error stating "Error: Invalid field ProcessNode for SObject ProcessInstanceHistory". I added it as the last column. How do I get the actual name of the step on there?

<apex:component controller="OrderApprovalHistoryControllerV2" access="global">
    <apex:attribute name="orderId" assignTo="{!orderId}" type="String" description="Id of the Order"/>  
    <apex:dataTable value="{!approvalSteps}" var="step" width="90%">
        <apex:column value="{!step.SystemModstamp}" headerValue="Date"/>
        <apex:column value="{!step.StepStatus}" headerValue="Status"/>
        <apex:column value="{!step.OriginalActorId}" headerValue="Assigned To"/>
        <apex:column value="{!step.ActorID}" headerValue="Actual Approver"/>
        <apex:column value="{!step.Comments}" headerValue="Comments"/>
        <apex:column value="{!step.ProcessNode.Name}" headerValue="Step Name"/> 
    </apex:dataTable>
</apex:component>
  • what is your component version. make sure its latest. – Tushar Sharma Sep 14 '17 at 18:52
  • I don't know how to check that. – MarvinM Sep 14 '17 at 18:55
  • go to component details page in org and there you see version setting click that and check SF api version. Make sure it is latest. – Tushar Sharma Sep 14 '17 at 18:58
  • Change it to 40 and your problem will be solved. – Tushar Sharma Sep 14 '17 at 19:02
  • Thank you. The node name is produced in the pdf now, but it isn't a column in the actual email body. Is there something I can do for that? – MarvinM Sep 14 '17 at 19:15
0

As your component version is 15 which is very older and ProcessNode.Name is not part of that. So just change the API to latest (eg. 40) and your problem will be solved.

  • @MarvinM is all other details are visible in your email body? – Tushar Sharma Sep 14 '17 at 19:19
  • Just the other fields I've called out to be displayed. I have Date, Status, Assigned To,Actual Approver,Comments displayed in the email. I would like the step name there too. It does show in the pdf though – MarvinM Sep 14 '17 at 19:21
  • @MarvinM if possible share the screenshot of your email which you have got. – Tushar Sharma Sep 14 '17 at 19:23
  • How do I add a screenshot here? – MarvinM Sep 14 '17 at 19:24
  • 1
    Neverming @Tuchar. I just had to reference the new controller where the email body was defined. Thank you so much for your help – MarvinM Sep 14 '17 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.