Usage of process var as delegate class for ServiceTask

Hey guys,

I’m a little bit confused about how to use a process var as delegate class in a ServiceTask.

I’m starting my process in the application:

Map<String, Object> processVars = new HashMap<String, Object>();
processVars.put("delegateClazz", "com.test.FooDelegate");
final ProcessInstance instance = runtimeService.startProcessInstanceByKey("simple-timer-task", processVars);

And that’s the corresponding process:

  <bpmn2:process id="simple-timer-task" isExecutable="true">
    <bpmn2:serviceTask id="ServiceTask_1" camunda:class="${delegateClazz}" name="Callback aufrufen">
    <bpmn2:sequenceFlow id="SequenceFlow_2" name="" sourceRef="ServiceTask_1" targetRef="EndEvent_1"/>
    <bpmn2:endEvent id="EndEvent_1">
    <bpmn2:startEvent id="StartEvent_2">
    <bpmn2:sequenceFlow id="SequenceFlow_3" name="" sourceRef="StartEvent_2" targetRef="ServiceTask_1"/>

And I’m ending up with error:
Caused by: java.lang.ClassNotFoundException: ${delegateClass}

Any solutions for this problem?

Hi Wischmopp,

Your problem is that the value of the camunda:class attribute is parsed as a string and not translated to an expression during the parsing of the BPMN.
As a workaround, you could use the camunda:delegateExpression attribute instead and define the value as a process variable like you already did. The process variable must return an instance of a class implementing the JavaDelegate interface.


1 Like

Hi Christian,

thank you very much for the quick response.
I’ve tried to set an ObjectValue instance with an instance of my Delegate Class, but now camunda is complaining about a missing serializer: Cannot find serializer for value 'ObjectValue
According to the docs camunda should be able to de-/serialize java objects out of the box…

Here’s my code:

        ObjectValue customerDataValue = Variables.objectValue(new TestDelegate())
        String instanceId = startProcessForContract(createdBy, "simple-timer-task", contractId, processVars);
        runtimeService.setVariable(instanceId, "delegate", customerDataValue);


Hi Andi,

Does the class TestDelegate implement


1 Like

Foooo, not my day :wink:
Thanks Thorben, now It’s working!!