Traversing the Account Tree

Mike Bray 's Avatar

Mike Bray

09 May, 2018 05:40 AM

I have hit an issue with traversing the tree of accounts. I thought that if you took the root account and traversed the tree by using:


 private void loadAccounts(Account parentAcct) {
    int sz = parentAcct.getSubAccountCount();
    for(int i=0; i<sz; i++) {
      Account acct = parentAcct.getSubAccount(i);

You would eventually load every account in the file. This does not seem to be happening. I have added a Security and it is not appearing in the hierarchy. Is there a different way of traversing the tree?

  1. Support Staff 1 Posted by Sean Reilly on 09 May, 2018 09:23 AM

    Sean Reilly's Avatar

    Hi Mike,
    That does look like it should work, but only if the security was added to an investment account. If you'd like a list of all securities you can get them from the AccountBook's CurrencyTable. A security is only represented by an account if it is used by one or more investment accounts.

    Another way to iterate over all accounts is using the AccountIterator ( The account iterator or functions such as AccountUtil.allMatchesForSearch() would be a bit faster as it doesn't rely on traversing the account hierarchy.


    Sean Reilly
    Developer, The Infinite Kind

  2. 2 Posted by Mike Bray on 09 May, 2018 03:45 PM

    Mike Bray 's Avatar

    Thanks Sean for the pointers. I will update my extensions accordingly.

  3. Mike Bray closed this discussion on 15 Jun, 2018 02:34 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac