Mendix Advanced Developer study materials
Mendix Advanced Developer study resources

Mendix Advanced Developer: Java Actions and Runtime Extensibility

Mendix Advanced Developer · Work through your exam, one topic at a time.

All guide sections

Java Actions and Runtime Extensibility

Structure

A Java action is a class extending CustomJavaAction<T> with a constructor taking IContext plus the declared parameters, and an executeAction() method that throws CoreException. Parameter and return types map to Mendix types: String, Long, Boolean (use the wrapper classes so null is representable), IMendixObject, List<IMendixObject> and member types. The action becomes available in the microflow toolbox once created in the modeler.

Core API

Use Core.create(context, Module.Entity), Core.commit(context, object), Core.retrieveXPathQuery(context, xpath), Core.delete(context, object) and getContext().getSession() for the current user. Objects created in Java are not persisted until committed. Retrieve with sort and range in the XPath instead of pulling a full list into memory.

Context and diagnostics

A Java action invoked from a scheduled event runs in a system context with no end user, so never assume getSession().getUser(context) is non-null. Use Core.getLogger(MyModule) rather than System.out, catch risky calls and rethrow CoreException so the calling microflow's error event can handle it.

Worked example

JA_NextInvoiceNumber retrieves Invoicing.Invoice sorted by Number descending with range 1, reads the first number, increments it and returns a String. Reasoning: the database does the ordering through the index on Number; a microflow retrieve plus list operation would transfer every invoice to compute the same value.

Traps

Returning a primitive long where the model expects Long; forgetting the commit so the caller holds an unsaved object; wrong case or missing module prefix in the entity string; heavy loops in Java without batching; assuming entity access is applied inside Java (a system context bypasses it).