2

Im trying to convert my opportunity page to PDF (tru my custom button PDF).. on the bottom of the opportunity page, there`s a section called Approval process and Stage History..

enter image description here

I tried some query to get the processInstance value, but I cant get the StepsAndWorkItems value..

ERROR sObject type 'StepsAndWorkitems' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.

and as the result, if I click the PDF button, there`s an error "Attempt to de-reference a null object"

Here`s my query

 piList = [SELECT Id, TargetObjectId, ProcessDefinition.Name, Status, CompletedDate, LastActor.Name,
                                    (SELECT Id, StepStatus, Actor.Name, OriginalActor.Name, Comments, ProcessNodeId, ProcessNode.Name, CreatedDate
                                    FROM StepsAndWorkitems ORDER BY Id DESC)
                                    FROM ProcessInstance WHERE TargetObjectId = :idsf ORDER BY Id DESC];

count2=0;
    wrppi = new List<wrapper>();
    wrppih = new List<wrapper>();
        for(ProcessInstance piL: piList){
            wrapper wpi=new wrapper();
            count2++;
            wpi.cou=count;
            wpi.pInstance = piL;
            wrppi.add(wpi);

            List<ProcessInstanceHistory> pihList2 = new List<ProcessInstanceHistory>();
            pihList2 = piL.getSObjects('StepsAndWorkitems');

                for(ProcessInstanceHistory pih: pihList2){
                    wrapper wrpih=new wrapper();
                    count3++;
                    wrpih.cou=count;
                    wrpih.piHistory = pih;
                    wrppih.add(wrpih);
                }
    } 

}

public class wrapper{
    Public integer cou {get;set;}
    Public OpportunityLineItem oppChild{get;set;}
    Public ProcessInstance pInstance{get;set;}
    Public ProcessInstanceHistory piHistory{get;set;}

}

And this is my vfpage

<div style="">
        <div Style="margin-top:15%; "  ><p Style="font-size:18px;" ><b>
            Approval History
            </b>
            </p>
            <table class="body" style = "text-align: center;font-size:14px; spacing:-1px; border:solid 1px black; ">
            <th style="width:10%; border:solid 1px black;">Date</th>
            <th style="width:10%; border:solid 1px black;">Status</th>
            <th style="width:10%; border:solid 1px black;">Assign To</th>
            <th style="width:10%; border:solid 1px black;">Actual Approver</th>
            <th style="width:15%; border:solid 1px black;">Comments</th>
            <th style="width:10%; border:solid 1px black;">Overall Status</th>

            <apex:repeat value="{!wrppi}" var="piObject">

               <tr>
                    <td style = "width:10%; text-align: center;font-size:14px; spacing:-1px; border:solid 1px black;">{!piObject.pInstance.CompletedDate}</td>

                    <td style = " width:10%; text-align: center;font-size:14px; spacing:-1px; border:solid 1px black;">{!piObject.pInstance.Status}</td>


                    <td style = "width:10%; text-align: center;font-size:14px; spacing:-1px; border:solid 1px black;">{!piObject.piHistory.Actor.Name}</td>


                    <td style = "width:10%; text-align: center;font-size:14px; spacing:-1px; border:solid 1px black;">{!piObject.pInstance.LastActor.Name}</td>


                    <td style = "width:10%; text-align: center;font-size:14px; spacing:-1px; border:solid 1px black;">{!piObject.piHistory.Comments}</td>


                    <td style = "width:10%;text-align: center;font-size:14px; spacing:-1px; border:solid 1px black;">{!piObject.piHistory.Comments}</td>
                </tr>

            </apex:repeat>
                    </table>
        </div> 
    </div>    

1 Answer 1

2

You need to use piL.StepsAndWorkitems

for(ProcessInstance piL: piList){
    //your existing code

    List<ProcessInstanceHistory> pihList2 = new List<ProcessInstanceHistory>();
    pihList2 = piL.StepsAndWorkitems;

        for(ProcessInstanceHistory pih: pihList2){

        }
    }

For more information, refer ProcessInstanceHistory

1
  • so sorry it takes forever for me to reply.. I totally forgot about this task, silly me.. Thanks for the reference!! now my pdf looks like what I wanted Jul 15, 2018 at 13:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .