2

how to create the object processInstance in test class?

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

0

1 Answer 1

5

Take a look at this Apex Approval Processing Example.

You should use the Approval.Process method (documentation).

public class ApprovalExample {
    void submitAndProcessApprovalRequest() {
        // Insert an account
        Account a = new Account(Name='Example');
        insert a;

        User user1 = [SELECT Id FROM User WHERE Alias='example'];

        // Create an approval request for the account
        Approval.ProcessSubmitRequest req1 = 
            new Approval.ProcessSubmitRequest();
        req1.setComments('Submitting request for approval.');
        req1.setObjectId(a.id);

        // Submit on behalf of a specific submitter
        req1.setSubmitterId(user1.Id); 

        // Submit the record to specific process and skip the criteria evaluation
        req1.setProcessDefinitionNameOrId('Example_Process');
        req1.setSkipEntryCriteria(true);

        // Submit the approval request for the account
        Approval.ProcessResult result = Approval.process(req1);

        // Now you have a ProcessInstance record
}

You must log in to answer this question.

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