Hi,
There are 2 common cases:
Use Core.retrieveByPath(...) with the association name (path).
import com.mendix.core.Core;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.systemwideinterfaces.core.IMendixObject;
import java.util.List;
public IMendixObject getReferencedObject(IContext context, IMendixObject o1) throws Exception {
// Replace with your module + association name
String assoc = "MyModule.Entity1_Entity2"; // association from Entity1 -> Entity2
List<IMendixObject> results = Core.retrieveByPath(context, o1, assoc);
// For reference (1-1), you typically get 0 or 1 object back
return results.isEmpty() ? null : results.get(0);
}
Same call, but you keep the list:
import com.mendix.core.Core;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.systemwideinterfaces.core.IMendixObject;
import java.util.List;
public List<IMendixObject> getReferencedSet(IContext context, IMendixObject o1) throws Exception {
String assoc = "MyModule.Entity1_Entity2"; // association from Entity1 -> Entity2
return Core.retrieveByPath(context, o1, assoc);
}
Thank you, Mohamed Shahi. It's working now.