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]


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.');

        // Submit on behalf of a specific submitter

        // Submit the record to specific process and skip the criteria evaluation

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

        // Now you have a ProcessInstance record

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.