You need to sign in to do that
Don't have an account?

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.
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.
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.
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.