Is it possible to generate a UML diagram for SF classes?

1,761 views
Skip to first unread message

gtand...@acumensolutions.com

unread,
Feb 23, 2017, 9:24:30 AM2/23/17
to Illuminated Cloud Q&A
I'm trying to find a tool that can inspect our classes and generate a UML diagram.  I've tried Code Navigator (won't even open the CRM project) and Code Iris (doesn't find anything to graph).
Any other options out there that anyone has used in the past?  This is specifically for mapping Apex class relationships so we can split up some of our shared classes.
Thanks!

Scott

unread,
Feb 23, 2017, 9:29:30 AM2/23/17
to Illuminated Cloud Q&A
Unfortunately right now I don't have the plugin wired into the IDE's native UML capabilities.  At a glance I found the following:


though I don't know how current those projects are at this point.  I'll be interested to hear others' responses on this as well.

Regards,
Scott Wells

gtand...@acumensolutions.com

unread,
Feb 24, 2017, 12:49:40 PM2/24/17
to Illuminated Cloud Q&A
So, some good news on this.  It's a bit of a pain, but in order to generate UML diagrams for apex classes, all you have to do is move the *.cls file type to Java.  Once that's done, the UML parser will accept *.cls files and you can generate the diagram.  Once you're done, switch it back to apex and you're good to go.

Ideally, I would love to find a way to either hack the plugin to support other extensions or file types, or build a plugin that piggy backs off of the UML plugin.

I had no luck with the Salesforce appexchange solutions.  They kept getting errors when trying to run on some larger Apex classes.

Scott

unread,
Feb 24, 2017, 12:56:13 PM2/24/17
to Illuminated Cloud Q&A
That's interesting...and more than a bit surprising!  I guess the UML diagram generator doesn't really need to parse the file as much as recognize some key patterns such as inheritance relationships via the "extends" and "implements" keywords.  Does it recognize Apex properties properly as fields in the diagram?  I'll play with it a bit myself to understand what does and doesn't work then see if there's anything I can to do make it a bit less onerous (which may just be providing a proper implementation).

Thanks for the update!
Scott

Roy Mayfield

unread,
Sep 11, 2017, 2:50:26 AM9/11/17
to Illuminated Cloud Q&A
First, what needs to be said.  Scott, the work you have done with this plug-in is nothing short of EXTRAORDINARY.  Your creativity and approach to solve The PAIN is *next level*.  <bows>.

On the diagram stuff, what a great idea gt!  I have to publish some classes tomorrow and this is perfect!!!  I can organize documentation based on selected classes.

I come from 2 decades of Visual Studio and I was simply catatonic when I saw the joke diagram of SFDC.  Garbage.

Since there is a workaround, this one has backlog written all over.  Peace

Scott

unread,
Sep 11, 2017, 9:03:37 AM9/11/17
to Illuminated Cloud Q&A
Roy, thanks for the nice note. Gotta say that something like this makes for a great way to start a Monday morning!

As you already noted, Gustavo deserves all the credit for this workaround. I'm still surprised that it works as well as it does...but it does, and I'll file this one into the "better to be lucky than good" pile.  Still, I would like this to make this easier for folks at some point by making it understand Apex as a first-class file type.

Best regards,
Scott

gtand...@acumensolutions.com

unread,
Mar 15, 2018, 5:54:49 PM3/15/18
to Illuminated Cloud Q&A

Really stupid update to this, but maybe it helps someone.

You can create symlinks in another folder (like UML) outside of src.  Symlinks are nice because they can have any extension (in this case: .java) and will link back to the original item.  You have to have a symlink for each file, not for the folder due to the extension thing.
So, something like this:


Then, run link.sh (source below and super ugly - sorry).  Set the Classes and Triggers folders as sources root and then you can generate the diagrams.

link.sh
#!/usr/bin/env bash
CLASSES="src/classes"
TRIGGERS="src/triggers"

# failing glob expands to nothing, rather than itself
shopt -s nullglob
mkdir -p "$CLASSES"
mkdir -p "$TRIGGERS"
for f in "../$CLASSES/"*.cls; do
file=$(basename "$f")
fp=$(realpath "$f")
ln -sfv "$fp" "$CLASSES/$file.java"
done
for f in "../$TRIGGERS/"*.trigger; do
file=$(basename "$f")
fp=$(realpath "$f")
ln -sfv "$fp" "$TRIGGERS/$file.java"
done
# unset this behaviour if you don't want it in the rest of the script
shopt -u nullglob

This results in this diagram:


spar...@gmail.com

unread,
Apr 20, 2018, 5:22:07 AM4/20/18
to Illuminated Cloud Q&A
But how to draw any UML diagram for a lightning project?

Scott

unread,
Apr 20, 2018, 9:59:24 AM4/20/18
to Illuminated Cloud Q&A
Unfortunately the hack to generate UML diagrams for Apex classes by making them look like Java classes won't work for Lightning. It looks like IntelliJ IDEA can draw a module dependency diagram for JavaScript but not a class diagram. Even if it could, it wouldn't really understand the Aura-specific relationships between components without a plugin that knows how to translate those relationships. For now I don't think there's any way to create a usable/useful UML diagram for Lightning in IntelliJ IDEA/IC. Sorry...

Regards,
Scott
Reply all
Reply to author
Forward
0 new messages