2

I need to insert some ProcessInstances to run a few tests, how do I do that?

I did it that way:

ProcessInstance pi1 = new ProcessInstance(Status = 'Approved', TargetObjectId = recordId1);
ProcessInstance pi2 = new ProcessInstance(Status = 'Pending', TargetObjectId = recordId2);
insert p1;
insert p2;

But the console log responds:

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [ProcessDefinitionId, CurrentNodeId]: [ProcessDefinitionId, CurrentNodeId]

Which values should I define for ProcessDefinitionId and CurrentNodeId ?

4

This is the way:

        Account acc1 = new Account(Name='acc1');
        insert acc1

        if([select count() from ProcessInstance where targetobjectid=:acc1.id] < 1)
        {       
            Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
            req.setComments('Approve.');
            req.setNextApproverIds(new Id[] {UserInfo.getUserId()});
            req.setObjectId(acc1.Id);

            //Submit the approval request
            Approval.ProcessResult result = Approval.process(req);

        }

Copied from: NO_APPLICABLE_PROCESS :No applicable process found!

0

This question and answer from the Salesforce.com Developer forum might help Errors with Unit Test for Approval Process Trigger

  • Can you try this insert pi1;insert pi2; – Ramesh S May 14 '14 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.