You need to sign in to do that
Don't have an account?
Raj88
Test class error
My class:
global class 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 ERS_Test_ApprovalRecall
{
static testMethod void testTrigger()
{
Deals__c deal = new Deals__c();
insert deal;
// Reject the submitted request, providing a comment.
Approval.ProcessWorkitemRequest testRej = new Approval.ProcessWorkitemRequest();
testRej.setAction ('Removed');
testRej.setWorkitemId(deal.id);
Test.startTest();
// Process the rejection
Approval.ProcessResult testRejResult = Approval.process(testRej);
Test.stopTest();
// Verify the rejection results
System.assert(testRejResult.isSuccess(), 'Rejections that include comments should be permitted');
System.assertEquals('Rejected', testRejResult.getInstanceStatus(),
'Rejections that include comments should be successful and instance status should be Rejected');
}
}
Error:
System.DmlException: Process failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []
Can anyone help me with this?
global class 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 ERS_Test_ApprovalRecall
{
static testMethod void testTrigger()
{
Deals__c deal = new Deals__c();
insert deal;
// Reject the submitted request, providing a comment.
Approval.ProcessWorkitemRequest testRej = new Approval.ProcessWorkitemRequest();
testRej.setAction ('Removed');
testRej.setWorkitemId(deal.id);
Test.startTest();
// Process the rejection
Approval.ProcessResult testRejResult = Approval.process(testRej);
Test.stopTest();
// Verify the rejection results
System.assert(testRejResult.isSuccess(), 'Rejections that include comments should be permitted');
System.assertEquals('Rejected', testRejResult.getInstanceStatus(),
'Rejections that include comments should be successful and instance status should be Rejected');
}
}
Error:
System.DmlException: Process failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []
Can anyone help me with this?
If you have the “manual Selection of approver” enabled for your approval process/steps then you must specify the approver in the trigger, else you will get an error something like:
“System.DmlException: Process failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, missing required field: []”
Please check the above and let me know.
read more: http://shivasoft.in/blog/salesforce/dynamic-approval-process-based-on-the-apex-and-trigger/