ExecutionQuery by processInstanceBusinessKey

Hi,

The following code works:
Execution execution = runtimeService.createExecutionQuery()
.messageEventSubscriptionName(“someSubscription”)
.singleResult();
runtimeService.messageEventReceived(“someSubscription”, execution.getId());

But this one results in a NPE on messageEventReceived line:
(the process was started using this business key)
runtimeService.createExecutionQuery().processInstanceBusinessKey(“SomeBusinessKey”)
.messageEventSubscriptionName(“someSubscription”).singleResult();
runtimeService.messageEventReceived(“someSubscription”, execution.getId());

The following code works, so the business key is correct:
ProcessInstance anInstance = runtimeService.createProcessInstanceQuery().processInstanceBusinessKey(“SomeBusinessKey”).singleResult();
System.out.println(anInstance.getId());

The business key is only set on the process instance execution, and not on child executions. Hence why the combination of business Key + message event subscription doesn’t work as there is no matching execution.
You will have to use 2 queries for this: first for the process instance and then one for the actual execution, using the processInstanceId from the first query.