Recently I was working for a requirement and got to know about Apexdoc for creating the documentation of all the classes in our org.
ApexDoc is a java app that we can use to document our Salesforce Apex classes. We need to tell ApexDoc where our class files are, and it will generate a set of static HTML pages that fully document each class, including its properties and methods. Each static HTML page will include an expandable menu on its left hand side, that shows a 2-level tree structure of all of our classes. Command line parameters allow us to control many aspects of ApexDoc, such as providing our own banner HTML for the pages to use.
- For using Apexdoc you need to install java JDK in your system and set its Path in the environment variable.
- For using apexdoc you need to install any IDE for salesforce like eclipse, sublime or VS code.
(I will explain the following example using eclipse)
Steps to use ApexDoc
- Download and install java JDK and set its Path in environment variable.
- Download and install eclipse.
- Download and Copy apexdoc.jar file to your local machine, somewhere on your path. (All my Source and target folder are in ‘C’ drive so I stored apexdoc.jar in C drive )
You can download apexdoc.jar from this link (https://github.com/SalesforceFoundation/ApexDoc/releases/tag/1.1.7)
- Make sure that java is on your path.
|-s source_directory||The folder location which contains your apex .cls classes. Ideally it is the folder ‘classes’ under your Eclipse IDE project setup on disc under “src” subfolder. The best is that you should first copy that classes folder somewhere on disc for example “D:\myproject\classes\”, and use this as source folder.|
|-t target_directory||This is to specify your target folder where documentation will be generated. If not given then it will generates the output documentation into current directory.|
|-g source_url||A URL where the source is hosted (so ApexDoc can provide links to your source). Optional.|
|-h home_page||The full path to an html file that contains the contents for the home page’s content area. Optional.|
|-a banner_page||The full path to an html file that contains the content for the banner section of each generated page. Optional.|
|-p scope||A semicolon separated list of scopes to document. Defaults to ‘global;public;webService’. Optional.|
Following are the Command Line Parameters that can be used in ApexDoc
Make sure that java is on your path. Invoke ApexDoc like this example:
java -jar apexdoc.jar
-s ‘/Users/dhabib/Workspaces/Force.com IDE/Cumulus3/src/classes’
java -jar apexdoc.jar -s C:\Users\teamabsyz\eclipseworkspace\forApexdoc3\src\classes -t C:\targetDirectory
C:\Users\teamabsyz\eclipse-workspace\forApexdoc3\src\classes is the path to my source class
C:\targetDirectory is the path of my Target Folder which I created to store the documents.
Documenting Class Files
ApexDoc scans each class file, and looks for comment blocks with special keywords to identify the documentation to include for a given class, property, or method. The comment blocks must always begin with /** (or additional *’s) and can cover multiple lines. Each line must start with * (or whitespace and then *). The comment block ends with */. Special tokens are called out with @token.
Located in the lines above the class declaration. The special tokens are all optional.
|@author||the author of the class|
|@date||the date the class was first implemented|
|@group||a group to display this class under, in the menu hierarchy|
|@group-content||a relative path to a static html file that provides content about the group|
|@description||one or more lines that provide an overview of the class|
Located in the lines above a property. The special tokens are all optional.
|@description||one or more lines that describe the property|
In order for ApexDoc to identify class methods, the method line must contain an explicit scope (global, public, private, testMethod, webService). The comment block is located in the lines above a method. The special tokens are all optional.
|@description||one or more lines that provide an overview of the method|
|@param param name||a description of what the parameter does|
|@return||a description of the return value from the method|
|@example||Example code usage. This will be wrapped in tags to preserve whitespace|
ScreenShot Of created Apexdoc
for the following class
/************************************************************************* * @description shows the list of All Account