Apex Cleaner
Format Apex code, remove blank lines, comment out System.debug statements (never inside catch blocks) and highlight them in red — for Salesforce Apex (.cls, .trigger, .apex).
Developer: Tilak Padole
Features
| Feature |
What it does |
| Format Code |
Re-indents by brace depth, adds continuation indent for multi-line calls / SOQL, trims trailing spaces, collapses repeated blank lines. |
| Remove Empty Lines |
Deletes all blank / whitespace-only lines. |
| Comment System.debug |
Turns System.debug(...) into // System.debug(...), including multi-line statements. Statements inside catch blocks are never touched. |
| Clean Code |
One click: remove empty lines → comment debug → format. |
| Method Comment |
Inserts a method header comment (@method, @purpose, @input, @output, @jiraTicket) above the method. Name, parameters and return type are filled in automatically. |
| Class Comment |
Inserts a class header comment (@description, @author, @date, @testClass, @jiraTicket) above the class. Class name, author and today's date are pre-filled. |
| Debug Highlight |
Commented-out System.debug lines are shown with a red background (and a red mark in the scrollbar). |
How to Use
1. Open an Apex file
Open any .cls, .trigger or .apex file in VS Code.
2. Run a command
Use either method:
- Right-click inside the editor and pick:
Apex: Clean Code
Apex: Comment System.debug
Apex: Toggle Debug Highlight
Apex: Insert Method Comment
Apex: Insert Class Comment
- Command Palette (
Ctrl+Shift+P / Cmd+Shift+P) and type Apex::
Apex: Clean Code
Apex: Format Code
Apex: Remove Empty Lines
Apex: Comment System.debug
Apex: Toggle Debug Highlight
Apex: Insert Method Comment
Apex: Insert Class Comment
3. Whole file or just a selection
- No selection → the command runs on the entire file.
- Select some lines → the command runs only on those lines.
Every command is applied as a single edit, so one Ctrl+Z undoes everything.
Apex Cleaner also registers as a formatter for Apex, so these work too:
Shift+Alt+F (Format Document) / Format Selection
- Auto-format on save — add to
settings.json:
"[apex]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "your-publisher-name.apex-cleaner"
}
Put the cursor on a method (or class) line and run Apex: Insert Method Comment / Apex: Insert Class Comment. The comment is added above the line (and above any @AuraEnabled / @isTest annotations). Press Tab to jump between the fields.
Method comment
/**
* @method : getAccounts
* @purpose :
* @input : String name, Integer lim
* @output : List<Account>
* @jiraTicket :
*/
Class comment
/**
* @description : Handles AccountService logic.
* @author : Tilak Padole
* @date : 2026-10-07
* @testClass :
* @jiraTicket :
*/
If the cursor is not on a class line, the comment goes above the first class / interface / enum in the file.
Snippets (type the prefix in an Apex file and press Tab): apexmethod or methodcomment for the method comment, and apexclass or classcomment for the class comment.
Example
Before
public class DemoService {
System.debug('start');
public void run() {
try {
System.debug('calling');
insert new Account(Name='Test');
} catch (Exception e) {
System.debug('Error: ' + e.getMessage());
}
}
}
After Apex: Clean Code
public class DemoService {
// System.debug('start');
public void run() {
try {
// System.debug('calling');
insert new Account(Name='Test');
} catch (Exception e) {
System.debug('Error: ' + e.getMessage()); // kept – inside catch
}
}
}
Apex: Format Code, Format Document and format-on-save also clean up /** ... */ header comments that use @tag : value lines. Colons are aligned, every line gets *, and extra lines are indented under the value.
/** /**
* @method : ddddd * @method : ddddd
* @input : * @input :
* @jiraTicket : ddd - dd ──► * @jiraTicket : ddd - dd
dd * dd
*/ */
Normal comments (/* ... */, or /** ... */ without @tag : lines) are not changed.
Settings
| Setting |
Default |
Description |
apexCleaner.collapseBlankLines |
true |
When formatting, collapse multiple consecutive blank lines into one. |
apexCleaner.highlightDebug |
true |
Highlight commented-out System.debug lines in red. |
apexCleaner.author |
"" |
Name filled into @author in class comments. |
apexCleaner.autoFillDate |
true |
Fill today's date into @date in class comments. |
apexCleaner.jiraTicket |
"" |
Default value for @jiraTicket in both comments. |
Indentation (tab size / spaces vs tabs) follows your current editor settings.
Notes
System.debug matching is case-insensitive (Apex is case-insensitive).
- Debug lines inside
catch (...) { } blocks are always left active, at any nesting depth.
- Lines inside
/* ... */ block comments are ignored.
- Red highlighting is visual only; it is not saved in the file.
License / Author
Developed by Tilak Padole.