public with sharing class PersonalProcessInstanceController { public List accPIList { get; private set; } public List conPIList { get; private set; } public List oppPIList { get; private set; } public List odrPIList { get; private set; } public List othPIList { get; private set; } private String userId; public Integer getAccPIListSize() { return accPIList.size(); } public Integer getConPIListSize() { return conPIList.size(); } public Integer getOppPIListSize() { return oppPIList.size(); } public Integer getOdrPiListSize() { return odrPIList.size(); } public Integer getOthPIListSize() { return othPIList.size(); } public PersonalProcessInstanceController() { userId = ApexPages.currentPage().getParameters().get('uid'); if (userId == null || userId == '') { userId = UserInfo.getUserId(); } } public PageReference init() { List piwList = [select id, ActorId, CreatedDate, ElapsedTimeInDays, OriginalActorId, ProcessInstance.TargetObjectId, ProcessInstance.Targetobject.Name, ProcessInstance.Status, ProcessInstance.SubmittedbyId, ProcessInstance.Submittedby.Name from ProcessInstanceWorkitem where ActorId = :userId order by ProcessInstance.TargetobjectId, CreatedDate asc]; Integer lineNo = 0; accPIList = new List(); conPIList = new List(); oppPIList = new List(); odrPIList = new List(); othPIList = new List(); if (piwList.size() > 0) { for (ProcessInstanceWorkitem piw : piwList) { lineNo += 1; String targetObjectId = piw.ProcessInstance.TargetObjectId; if (targetObjectId.startsWith('001') == true) { // account ProcessInfo newpi = new ProcessInfo(lineNo, piw, 'account'); accPIList.add(newpi); } else if (targetObjectId.startsWith('003') == true) { // contact ProcessInfo newpi = new ProcessInfo(lineNo, piw, 'contact'); conPIList.add(newpi); } else if (targetObjectId.startsWith('006') == true) { // opportunity ProcessInfo newpi = new ProcessInfo(lineNo, piw, 'opportunity'); oppPIList.add(newpi); } else if (targetObjectId.startsWith('801') == true) { // order ProcessInfo newpi = new ProcessInfo(lineNo, piw, 'order'); odrPIList.add(newpi); } else { // others ProcessInfo newpi = new ProcessInfo(lineNo, piw, 'other'); othPIList.add(newpi); } } } return null; } class ProcessInfo { public Integer lineNo { get; private set; } public ProcessInstanceWorkitem piw { get; private set; } public Decimal elapsedTimeInDays { get; private set; } // accpunt,contact,opportunity,order,other public String pType { get; private set; } public ProcessInfo(Integer in_no, ProcessInstanceWorkitem in_piw, String in_pType) { lineNo = in_no; piw = in_piw; pType = in_pType; elapsedTimeInDays = in_piw.ElapsedTimeInDays; elapsedTimeInDays = elapsedTimeInDays.setScale(1); } } }