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 ?

2 Answers 2

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
0

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

1
  • Can you try this insert pi1;insert pi2; Commented May 14, 2014 at 15:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .