Apex · Salesforce

Apex Documentation Using ApexDoc

Hi All,

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

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.

Requirements

  1. For using Apexdoc you need to install java JDK in your system and set its Path in the environment variable.
  2. 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

  1. Download and install java JDK and set its Path in environment variable.
  2. Download and install eclipse.
  3. 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)

  1. Make sure that java is on your path.

 

 

 

parameter description
-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

Usage

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’

-t ‘/Users/dhabib/Dropbox/Cumulus/ApexDoc’

-p ‘global;public;private;testmethod;webService’

-h ‘/Users/dhabib/Dropbox/Cumulus/ApexDoc/homepage.htm’

-a ‘/Users/dhabib/Dropbox/Cumulus/ApexDoc/projectheader.htm’

-g ‘http://github.com/SalesforceFoundation/Cumulus/blob/dev/src/classes/’

 

Example command

java -jar apexdoc.jar  -s C:\Users\teamabsyz\eclipseworkspace\forApexdoc3\src\classes -t C:\targetDirectory

Where :

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.

Class Comments

Located in the lines above the class declaration. The special tokens are all optional.

token Description
@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

 

Property Comments

Located in the lines above a property. The special tokens are all optional.

token description
@description one or more lines that describe the property

 

Method Comments

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.

token description
@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

class.png

/*************************************************************************     * @description shows the list of All Account

 

Apexdoc.png}

 

 

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s