+ Start a Discussion
deep123456789deep123456789 

Help need in writing test method

To create test data i need to insert some value in ProcessInstanceWorkitem .But it is not allowed.I am using ProcessInstanceWorkitem  to identify all the approvals that are pending for approval.

Can any one help to write a test method for this method given below.I need this urgently.



public static void notifyDelegatedApprover(){
   
    
     List <ProcessInstanceWorkitem> pendingApprovalList=null;
     pendingApprovalList=[Select p.SystemModstamp, p.ProcessInstance.TargetObjectId,
     p.ProcessInstance.TargetObject.name,p.OriginalActorId, p.IsDeleted, p.Id,
     p.CreatedDate, p.CreatedById,p.ActorId,p.Actor.name,p.Actor.Email
     From ProcessInstanceWorkitem p];
    
       
     for(ProcessInstanceWorkitem pendingObj:pendingApprovalList){
       System.debug('Pending Approval --actual approvers id ------'+pendingObj.ActorId); 
       System.Debug('Target Object Id------------'+pendingObj.ProcessInstance.TargetObject.name);
       approverUserIdSet.add(pendingObj.ActorId);
     }
     System.Debug('----pendingApprovalList  Size-----------'+pendingApprovalList.size());
    
     for(User approvers:[select Id,DelegatedApproverId,Vacation_Start_Date__c,Vacation_End_Date__c
                                    from User
                                    where id in:approverUserIdSet
                                    and Vacation_Start_Date__c <> null
                                    and Vacation_End_Date__c <> null
                                    and DelegatedApproverId <> null]) {
            if (approvers.Vacation_Start_date__c < System.today() && approvers.Vacation_End_date__C > System.today()) {
                System.debug('Delegated Approver Id------'+approvers.DelegatedApproverId);
                delegatedApproverUserIdSet.add(approvers.DelegatedApproverId);
                approversOnVacation.add(approvers.Id);
                if(delegatedApproversMap.get(approvers.Id) == null) delegatedApproversMap.put(approvers.Id, approvers.DelegatedApproverId);
            }
        }
       
        //send email notification
        sendMail(getDelegatedApproverEmail(delegatedApproverUserIdSet),getMessage());
   
    }