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
Raj88Raj88 

Test class for Recall approver

Class:

global class Cls_ApprovalRecall
{
    webservice static void recallApproval(Id recId)   
    {       
        ID piwiID = [SELECT Id, ProcessInstanceId, ProcessInstance.TargetObjectId FROM ProcessInstanceWorkitem WHERE ProcessInstance.TargetObjectId =: recId].ID;
        Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
        req.setAction('Removed');       
        req.setWorkitemId(piwiID );
  
        Approval.process(req,false);
    }
}


Test class:
@isTest
private class Test_ApprovalRecall
{
static testMethod void testClass()
{
Cls_ApprovalRecall app = new Cls_ApprovalRecall();

    Deals__c deal = new Deals__c();
    deal.Status__c='ACT';
    deal.DateEnd__c=Date.newInstance(2013,12,01);
    insert deal;  

id recId=deal.id;

Test.StartTest();
List<ProcessInstance> processInstances = [select Id, Status from ProcessInstance where TargetObjectId = :deal.id];
Cls_ApprovalRecall.recallApproval(recId);
Test.StopTest();

}
}


Error:

List has no rows assigned to sobject.
CheyneCheyne
Although I don't know for sure which line is producing the error, it seems like it's the first line in the recallApproval routine, which starts with "Id piwiID". Most likely, the relevant ProcessInstance record does not exist within the context of the test class.

Since, your test class is not explicitly inserting a ProcessInstance record, are you sure that a ProcessInstance record is being created as a result of inserting a Deal__c record? It also may be helpful, in your webservice, to check for the existence of the ProcessInstance before trying to get its ID, either with a try/catch block or by retrieving your ProcessInstance as a list and then checking that the size is greater than zero.


Vinita_SFDCVinita_SFDC
Hello,

Try using seystem.debug statements in your test class to check if the records has inserted and query is returning expected results,

You can check logs in developer console.