function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Justin NorrisJustin Norris 

Documenting Your Apex Code - Best Practices?

Hi all, 

Our org is leaning on Apex more and more to solve particular problems. Personally I go to code as a last resort since I am a button-click admin and declarative automations are a lot easier for me to maintain, but sometimes it's the only way. 

Anyhow, now that we are building up a decent amount of Apex code I want to document this thoroughly. 

Both so other people can easily see what has happened, and so that I can easily answer the question, 

"do we have any apex code that touches ______" 

And just basically so I can keep my house in order. 

Anyways, I am wondering if anyone has any best practices, samples, or templates about how you document your code? 

In fact, documentation of workflows and anything else would be of interest to, because we don't do any of that right now. 

I figured some smart people out there have figured this out before, so why should I reinvent the wheel! :) 

Appreciate anything you can share. 
Best Answer chosen by Justin Norris
pconpcon
We use just standard javadoc [1] to document our code.  It's a pretty nice standard and it allows you to run SfApexDoc [2] against your code to have a more easily browsable code base.  You might also want to look this post [3] to see how you can see what code / methods are not being used (full disclosure: I've not had a chance to try this out, but I know Andy and it should at least be worth looking at).

As for documentation of workflows and other things, we make a effort to have every one of our fields documented in our objects (even if it's putting a description of [UNUSED] in them).  We've written some internal tooling that displays object data on a angular page so that our external developers know the API names and structure of the objects.

The biggest thing that has helped us as for as organization goes is storing everything in git [4] and having each commit tied to a unit of work either a User Story (from rally) or a Bug (from bugzilla).  This way we can look back at the history to see what has been done and who did it.  It was a little tough to get our non-developers over to git but it was worth it in the long run.

[1] http://en.wikipedia.org/wiki/Javadoc
[2] https://gitlab.com/StevenWCox/sfapexdoc
[3] http://andyinthecloud.com/2013/02/02/spring-cleaning-apex-code-with-the-tooling-api/
[4] http://blog.deadlypenguin.com/blog/2014/07/21/using-git-with-salesforce-and-distributed-teams/

All Answers

pconpcon
We use just standard javadoc [1] to document our code.  It's a pretty nice standard and it allows you to run SfApexDoc [2] against your code to have a more easily browsable code base.  You might also want to look this post [3] to see how you can see what code / methods are not being used (full disclosure: I've not had a chance to try this out, but I know Andy and it should at least be worth looking at).

As for documentation of workflows and other things, we make a effort to have every one of our fields documented in our objects (even if it's putting a description of [UNUSED] in them).  We've written some internal tooling that displays object data on a angular page so that our external developers know the API names and structure of the objects.

The biggest thing that has helped us as for as organization goes is storing everything in git [4] and having each commit tied to a unit of work either a User Story (from rally) or a Bug (from bugzilla).  This way we can look back at the history to see what has been done and who did it.  It was a little tough to get our non-developers over to git but it was worth it in the long run.

[1] http://en.wikipedia.org/wiki/Javadoc
[2] https://gitlab.com/StevenWCox/sfapexdoc
[3] http://andyinthecloud.com/2013/02/02/spring-cleaning-apex-code-with-the-tooling-api/
[4] http://blog.deadlypenguin.com/blog/2014/07/21/using-git-with-salesforce-and-distributed-teams/
This was selected as the best answer
Justin NorrisJustin Norris
@pcon, thanks so much for this. Gives a great idea of how you are approaching it and some things I had never thought of. Much appreciated. 
pconpcon
Glad it helped.  If you do not mind, please mark the "Best Answer" on this post so that it can be removed from the unanswered queue and help people in the future.
JP HendrixJP Hendrix
Hello - so I'm coming onto this thread many years afterwards. SFApexDoc seems not to have been updated in awhile (perhaps it doesn't need it?). Are there any new tools and techniques here? :-)