How to get the list of child records using parent record in Java Action?

Hi All, I have two objects Account and Contact. There is 1-* relationship between them where Account being the parent. When the user delete the Account record, it will deletes all the related contacts. I am writing a Java action to export all accounts and related contacts to an excel file. So I tried to retrieve the Contact records using Account, I couldn't find the relation between them in eclipse IDE. Why I am unable to see the relation in IDE? Please help me with this. It would be great if you can give me an alternative to achieve this. Thanks in advance. Regards, Venkat
3 answers

You can easily do the retrieve in a microflow which you call from your java code. This is the cleanest and simplest way to accomplish this.

Hope this helps,



Couple of things:

  1. The equivalent of retrieving over association in a microflow is Core.retrieveByPath(something something). This will retrieve from memory if possible (just like retrieve over association in a microflow). You could of course retrieve by xPath if what you really want is to always retrieve from database.
  2. Please use the XPath helper class from Community Commons for creating XPath queries.
  3. Contact.MemberNames.Contact_Account is not a String. You would need to add a .toString() if you need a String.
  4. I am not saying it's wrong that you need to resort to Java do do this, but is is a bit suspicious. Are you sure you cannot handle this use-case in only microflows?



1-* Associations are always stored on the many side, so it’s not that you cannot see it, it just isn’t available on your side.

Mendix writes the retrieves for the users in this case. If you want to do it in Java, you’ll have to do a retrieve on contracts with an XPath that references the Account’s identifier.

In the java documentation you will find the method you need under ICore.retrieveXpathQuery.

Edit: Here’s how I believe your query will look

String myQuery = String.format("//%s[%s="+ account.getId().toString()+"]",Contact.entityName,Contact.MemberNames.Contact_Account.toString());

Hope this helps