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

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.setWorkitemId(piwiID );

Test class:

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');
            // Process the rejection
            Approval.ProcessResult testRejResult =  Approval.process(testRej);
        // 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');

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?
One possible cause might be the following:

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: