{"record":{"id":"96cf78b0766944de","repo":"flowable/flowable-engine","slug":"no-process-instance-found-for-id-processinstan","errorCode":null,"errorMessage":"No process instance found for id = '<processInstanceId>'.","messagePattern":"No process instance found for id = '<processInstanceId>'\\.","errorType":"exception","errorClass":"ActivitiObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/SetProcessInstanceBusinessKeyCmd.java","lineNumber":55,"sourceCode":"\n    public SetProcessInstanceBusinessKeyCmd(String processInstanceId, String businessKey) {\n        if (processInstanceId == null || processInstanceId.length() < 1) {\n            throw new ActivitiIllegalArgumentException(\"The process instance id is mandatory, but '\" + processInstanceId + \"' has been provided.\");\n        }\n        if (businessKey == null) {\n            throw new ActivitiIllegalArgumentException(\"The business key is mandatory, but 'null' has been provided.\");\n        }\n\n        this.processInstanceId = processInstanceId;\n        this.businessKey = businessKey;\n    }\n\n    @Override\n    public Void execute(CommandContext commandContext) {\n        ExecutionEntityManager executionManager = commandContext.getExecutionEntityManager();\n        ExecutionEntity processInstance = executionManager.findExecutionById(processInstanceId);\n        if (processInstance == null) {\n            throw new ActivitiObjectNotFoundException(\"No process instance found for id = '\" + processInstanceId + \"'.\", ProcessInstance.class);\n        } else if (!processInstance.isProcessInstanceType()) {\n            throw new ActivitiIllegalArgumentException(\n                    \"A process instance id is required, but the provided id \" +\n                            \"'\" + processInstanceId + \"' \" +\n                            \"points to a child execution of process instance \" +\n                            \"'\" + processInstance.getProcessInstanceId() + \"'. \" +\n                            \"Please invoke the \" + getClass().getSimpleName() + \" with a root execution id.\");\n        }\n\n        processInstance.updateProcessBusinessKey(businessKey);\n\n        return null;\n    }\n}\n","sourceCodeStart":37,"sourceCodeEnd":70,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/SetProcessInstanceBusinessKeyCmd.java#L37-L70","documentation":"execute() resolves the process instance with findExecutionById and throws ActivitiObjectNotFoundException (typed ProcessInstance.class) when no execution matches the supplied processInstanceId. The engine therefore never writes a business key because the target instance does not exist at runtime.","triggerScenarios":"runtimeService.setBusinessKey(pid, key) with a pid for an instance that already completed, was deleted, or never existed on this engine/database.","commonSituations":"Setting the key asynchronously after the instance finished; ids copied between test/dev and prod databases; replayed messages referencing deleted instances.","solutions":["Check existence first with runtimeService.createProcessInstanceQuery().processInstanceId(pid).count().","If the instance is finished, write the key to history or your own audit store instead of the runtime API.","Confirm engine/database alignment in multi-engine deployments.","Catch ActivitiObjectNotFoundException and treat it as a benign no-op if the instance may have completed concurrently."],"exampleFix":"// before\nruntimeService.setBusinessKey(pid, key);\n// after\nProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(pid).singleResult();\nif (pi == null) {\n    log.warn(\"Skipping business key update; instance {} not running\", pid);\n    return;\n}\nruntimeService.setBusinessKey(pid, key);","handlingStrategy":"validation","validationCode":"if (runtimeService.createProcessInstanceQuery().processInstanceId(pid).count() == 0) {\n    throw new IllegalStateException(\"Process instance \" + pid + \" is not running\");\n}","typeGuard":"boolean isRunning(RuntimeService rs, String pid) {\n    return pid != null && rs.createProcessInstanceQuery().processInstanceId(pid).count() > 0;\n}","tryCatchPattern":"try {\n    runtimeService.setBusinessKey(pid, key);\n} catch (org.activiti.engine.ActivitiObjectNotFoundException e) {\n    // instance ended or never existed\n}","preventionTips":["Confirm the instance is running before runtime mutations","Treat completed-instance updates as history/audit operations instead"],"tags":["java","flowable","entity-not-found","process-instance"],"backgroundTag":"entity-not-found","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}