I have a many-to-many relationship between accounts. Somewhat like below:

A B   
| |
| | |

I want to give the user a nice hierarchical view to see all the parents (including grandparents, grand-grand parent) of an account as well all the children up to the lowermost level. Are there any Appexchange applications (free) that can give me an idea of how the relationship can be represented?

  • 2
    You want us to do research for you? What have you tried sofar? – Sergej Utko Aug 22 '14 at 9:42
  • Definitely lot, there could be someone, who might have had the same requirement and came accross some apps that can be used. However, I coul;d find this appexchange.salesforce.com/…, which is not a suitable option for me, given the fact I can have an account with several parents. – ParoTech Aug 22 '14 at 9:52
  • @mast0r I like this kind of generic questions as long as the OP can accept, that we also can only respond by generic solution concepts and ideas. In fact it think it's an interesting use case. We have more than one client having this kind of networked account-relationships, but we never visualized it. Could be a nice app and I thinks about writing it myself. – Uwe Heim Aug 22 '14 at 10:44
  • @ParoTech on thing you should keep in mind: this kind of structures could be hard to handle with salesforce reporting later. Depending on the requirements you may have a hard (and I mean very hard) time creating reports based on the m:n relationship. – Uwe Heim Aug 22 '14 at 10:52
  • @UweHeim Don't forget about How to ask. Just a short research will give a lot of ideas already exist . – Sergej Utko Aug 22 '14 at 11:02

You could try it write it yourself. Would be a two step process:

  • First you have to fetch the data from the database into a appropriate data-structure.
  • Second you have to visualize it

Fetch data

An first approach would be to start with a given account C upstream querying for parents. Querying one level at a time is usually trivial. You could repeat it by recursion or loops. Your final-upstream leafs are reached when there are no further parents left. Downstream you do the same but for children.

But this is not all. You want the network (or graph), and now you have it:

  • A serious challenge are loops (cyclic relations). I would recommend that you disallow them by definition and validation. If you need them, you need to detect them and prevent endless loops or recursions.
  • Networks starting at different nodes. In your example E could have other parents than C. I would recommend to start keeping this out-of-scope for version 1.
  • The kind of data-structure you choose as target is highly dependent on your rendering solution. If you pick a JS-renderer (what you will most likely do) one possibility could be to avoid creating structures in apex but start to create only a string of JavaScript commands to be output on a page.


Depending on having cycles banned or not, rendering can be a challenge.

A very short research brought something up - at least one with a funny name http://www.graphdracula.net/ :-) and it really looks promising. On the page there are also links to similar JS projects.

Now if you look at the example code, you also see what you basically need for this lib: edges and nodes. Try to fetch them from the database.

enter image description here

  • Interesting that what you came up with looks very similar to SF's schema builder. ;) – crmprogdev Aug 22 '14 at 15:39
  • 1
    This sparked my curiosity - and came up with this option (untried) - almende.github.io/chap-links-library (See the Network example) - It operates as a Google Visualization Chart which can be embedded in a VF page. – cropredy Aug 22 '14 at 22:37
  • @crop1645 that also looks very promising, thanks for sharing this link. – Uwe Heim Aug 23 '14 at 14:00

You could try writing a visualforce page and using jQuery, perhaps a treeview would represent it well (http://plugins.jquery.com/tag/treeview/).

  • I think a treeview is not the right type of ui-control, since the multiple parents in the requirements. It's a network-structure not a tree-structure. – Uwe Heim Aug 22 '14 at 10:14
  • Hmmm, good point, it would be more of a network. The tree would only really work if you were at the top level parent. If there can be lots of parents and children then it could be quite a cluttered visualisation. – Doug B Aug 22 '14 at 10:18
  • The proper term for the structure would be "Graph" I guess. – Uwe Heim Aug 22 '14 at 10:45
  • Yes Uwe Heim, I think the Graph structure should represent the relationship best in this case. I will try the best options and see how the result comes. – ParoTech Aug 25 '14 at 6:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.