function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ayush Kumar 31Ayush Kumar 31 

Testing issues

While running a test class for below piece of code it hits exception at the Bold part of the code, can anyone help??
for(PP_RequestToFill_Master__c obj: poslist){          
                Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();           
                req.setComments(ApprovingRequest);
                req.setAction(Approve);                    
                ProcessInstanceWorkitem workItem = getWorkItemId(obj.id);  
                system.debug('workitem'+workItem);
                if(workItem.Id == null)                                    <----------------------Here exception is thrown and the code stops executing further
                {
                    obj.addError(TriggerError);
                    outputResult = false;                
                }
                else
                {
                    req.setWorkitemId(workItem.Id);
                    Approval.ProcessResult result =  Approval.process(req);
                    outputResult = result.isSuccess();
                }
            }
Manj_SFDCManj_SFDC
Hello I think your workitem is empty , can you please check what is been printed from  system.debug('workitem'+workItem);, you can do this 
 instead of  if(workItem.Id == null)    you can do this if(workItem == null)  
Manj_SFDCManj_SFDC
Mark this as solved if this helped you, you too will fetch some points if the question is marked as solved :)
https://developer.salesforce.com/forums#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Developer_Forums&criteria=ALLQUESTIONS&id=9060G000000MVrtQAG